xml - Restrict execution of xsl:template to specified number of times -
here's xslt:
<!-- looping through both items , categories of items --> <xsl:for-each select="statement"> <!-- define whether current node single item or category of items --> <xsl:choose> <!-- category of items --> <xsl:when test="statement"> <!-- render items in category --> <xsl:for-each select="statement"> <xsl:call-template name="renderitem" select="current()" /> </xsl:for-each> </xsl:when> <!-- single item --> <xsl:otherwise> <xsl:call-template name="renderitem" select="." /> </xsl:otherwise> </xsl:choose> </xsl:for-each>
i want able output specific number of items, not of them. how create "renderitem" executed not more than, say, 4 times?
your code looks pretty odd: xsl:choose, xsl:for-each, , xsl:call-template looks home-made implementation of apply-templates , template rules. moreover, xsl:call-template not take select attribute - that's syntax error , xslt processor should flag such, not ignore it.
ignoring that, think simplest solution problem test whether want process item examining position in tree. like
<xsl:template match="statement"> <xsl:variable name="pos"> <xsl:number level="any" from="..."/> </xsl:variable> <xsl:if test="$pos < 5">... </xsl:template>
xml xslt loops
No comments:
Post a Comment