| Basic sort and apply templates
|
Claes100

msg:4455344 | 3:46 pm on May 19, 2012 (gmt 0) | Hi, I have an XML file with a large number of terms and abbreviations that I sort and output to a pdf document. The output is sorted nicely but after the last term the whole content is output AGAIN, this time in the order itīs written in the XML. I think I lack the most basics regarding xsl:sort and xsl:apply-templates... :)) Please give me a hint, thanks! (How do I indent code...? Spaces?) XML:
<element type=""> <title>Terminology</title> <body> <glossentry> <glossterm>TERM 1</glossterm> <glossdef> <para>Explanation 1</para> </glossdef> </glossentry> <glossentry> <glossterm>TERM n</glossterm> <glossdef> <para>Explanation n</para> </glossdef> </glossentry> </body> </element>
XSLT:
<xsl:template match="title"> <fo:block font-size="20pt" font-family="Helvetica" line-height="24pt" space-after.optimum="20pt" text-align="left" font-weight="bold"> <xsl:value-of select="."/> </fo:block> <xsl:if test="/element/@type='term'"> <xsl:apply-templates select="/element/body/glossentry"> <xsl:sort select="glossterm" order="ascending"/> </xsl:apply-templates> </xsl:if> </xsl:template>
<xsl:template match="glossterm"> <fo:block font-weight="bold" font-size="11pt"> <xsl:apply-templates/> </fo:block> </xsl:template>
<xsl:template match="glossdef"> <fo:block> <xsl:apply-templates/> </fo:block> </xsl:template>
<xsl:template match="para"> <fo:block font-family="serif" font-size="11pt" line-height="14pt" space-after.optimum="10pt"> <xsl:apply-templates/> </fo:block> </xsl:template>
|
Claes100

msg:4455862 | 9:30 am on May 21, 2012 (gmt 0) | Ok, found the solution. Changes in "template match='title'" and an added, empty "template match='glossentry'": : : <xsl:if test="/element/@type='term'"> <xsl:apply-templates select="//glossterm"> <xsl:sort select="." data-type="text" lang="en" order="ascending" /> </xsl:apply-templates> </xsl:if> <xsl:template match="glossentry"> <!-- Do nothing --> </xsl:template> <xsl:template match="glossterm"> <xsl:variable name="termId"><xsl:value-of select="../@id"/></xsl:variable> <fo:block font-weight="bold" font-size="11pt"> <xsl:apply-templates/> <xsl:if test="ancestor::element//glosssee[@otherterm = $termId]"> <xsl:text>
(</xsl:text><xsl:value-of select="ancestor::element//glossterm[following-sibling::glossdef/glosssee/@otherterm = $termId]"/>) </xsl:if> </fo:block> <xsl:apply-templates select="../glossdef"/> </xsl:template> /Claes
|
|
|