At work I’ve been given the fun task of generating PDFs with XSL. The XML structure I’m working with is similar to
<records> <topLevel> <topLevelID></topLevelID> <secondLevel> <secondLevelID></secondLevelID> <thirdLevel> </thirdLevel> <thirdLevel> </thirdLevel> </secondLevel> </topLevel> <topLevel> <topLevelID></topLevelID> <secondLevel> <secondLevelID></secondLevelID> <thirdLevel> </thirdLevel> <thirdLevel> </thirdLevel> </secondLevel> </topLevel> </records>
I would try to give a more meaningful example of the XML, but I don’t feel like approaching any legal boundaries that may exist. With that XML structure, I have to output a block of text in the PDF for every thirdLevel node. The XSL I have so far is like
<xsl:for-each select ='topLevel'> <xsl:variable name='topID' select='topLevelID'/> <xsl:for-each select ='secondLevel'> <xsl:variable name='secondID' select='secondLevelID'/> <xsl:for-each select='thirdLevel'> <fo:block-container position='absolute' height='12.8pt' width='220.8pt' left='160pt' display-align='auto'> <xsl:attribute name='top'> <xsl:value-of select='concat(193 + [whatshouldgohere]), 'pt')'/> </xsl:attribute> <fo:block font-size='7pt'> <xsl:call-template name='insertThirdLevel'/> </fo:block> </fo:block-container> </xsl:for-each> </xsl:for-each> </xsl:for-each>
Basically, I need to add some value to the top attribute to make the text for each thirdLevel node appear on its own line. I’ve tried using combinations of adding/multiplying by the ID (starts at 1 and increases by 1 for each set) and position(), but I can’t seem to get it right.
I think you should really look into
<xsl:apply-templates>, it can save you a lot of typing.Simplified version:
Simplified output (‘fo’ namespace excluded):