[Home] [By Thread] [By Date] [Recent Entries]
Ganesh Babu N wrote:
all those should be clubbed into single section by taking group-adjcent. If you know that you want group-adjacent then it is only a slight change from the earlier stylesheet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="articles"> <sections> <section-title>Contents</section-title> <xsl:for-each-group select="row" group-adjacent="if (col[2] = '') then '' else tokenize(col[2], '\|')[1]"> <xsl:choose> <xsl:when test="contains(col[2], '|')"> <xsl:variable name="outer-key" select="current-grouping-key()"/> <xsl:for-each-group select="current-group()" group-by="tokenize(col[2], '\|')[2]"> <section> <xsl:if test="position() eq 1"> <section-head><xsl:value-of select="$outer-key"/></section-head> </xsl:if> <section-subhead><xsl:value-of select="current-grouping-key()"/></section-subhead> <xsl:apply-templates select="current-group()"/> </section> </xsl:for-each-group> </xsl:when> <xsl:otherwise> <section> <section-head><xsl:value-of select="current-grouping-key()"/></section-head> <xsl:apply-templates select="current-group()"/> </section> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </sections> </xsl:template> <xsl:template match="row">
<para>
<page><xsl:value-of select="col[3]"/></page>
</para>
</xsl:template>
</xsl:stylesheet>The problem why the previous solution skips the row elements with an empty col[2] child element is that the tokenize function returns an empty sequence for the empty string and that does not result in a group. But group-adjacent="if (col[2] = '') then '' else tokenize(col[2], '\|')[1]" avoids that problem and simply form a group for those elements with an empty col[2]. -- Martin Honnen http://msmvps.com/blogs/martin_honnen/
|

Cart



