[thelist] xsl:for-each "breaking" after processing several elements?

Anthony Baratta anthony at baratta.com
Sun Jun 10 23:29:16 CDT 2007


Zdravko Beykov wrote:
> I face the following problem - I have an xml document that contains
> players with their rankings, and I would like to output the top five
> players, and don't do anything with the others.
> I would use xsl:for-each and xsl:sort, but how can i keep track if i have
> already outputted 5 players (i mean i can't keep a counter in xsl due to
> the nature of the variables in xsl).

If I'm following you correctly, just check the position of the node you 
are on after you sort. Ignore all nodes greater than five.

e.g.

<xsl:if test="(position() &lt; 6)>

blah blah blah

</xsl:if>



More information about the thelist mailing list