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

Eduardo Kienetz eduardok at gmail.com
Sun Jun 10 23:33:26 CDT 2007


On 6/11/07, Anthony Baratta <anthony at baratta.com> wrote:
> 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>

Another option you have, if I remember right, is to select only those
5 in your xpath:

<xsl:for-each select="players[position()&lt;6]">
do something here.
</xsl:for-each>

-- 
Eduardo Bacchi Kienetz
LPI Certified - Level 2
http://www.noticiaslinux.com.br/eduardo/



More information about the thelist mailing list