Counting in <xsl:for-each>

admin

Administrator
Staff member
How can I count while running through a <xsl:for-each>? What I want to do is basically generate different names for every element parsed this way: name0, name1, name 2, ...

What I though of was generating a variable and then adding 1 each time the for-each is run:


<xsl:variable name="counter" select="0" />
<xsl:for-each select="...">
<xsl:variable name="counter" select="sum($counter+1)" />
</xsl:for-each>


This does not seem to work. Excuse my ignorance - I'm sure there is a much simpler solution, but I'm quite new at XSL and it's just a little thing I need to do. Thanks for you help!
 
Back
Top