How to use a counter in a XSL Loop (xsl:for-each)

To use a counter in a XSL For-Each block, you can use the position() function, the Counter starts at value 1.

Sample XSL

<xsl:for-each select="Order/Products/Product">
    <position><xsl:value-of select="position()"></xsl:value-of></position>
</xsl:for-each>

see also MSDN position Function

Please Share us:
Please rate this snippet

Leave a Reply