There is list
<nodes>
<node attr='1'/>
<node attr='0'/>
<node attr='1'/>
<node attr='1'/>
</nodes>
i need to apply-templates all nodes and count it:
<xsl:apply-templates select='nodes/node'>
<xsl:if test='@attr=1'>
<xsl:number/>
</xsl:if>
</xsl:apply-templates>
but a haz in result not 123, result is 134. How to fix it in xslt-1.0? There is another way to set numbers to it? position() not help, and
<xsl:apply-templates select='nodes/node[@attr=1]'>
<xsl:if test='@attr=1'>
<xsl:number/>
</xsl:if>
</xsl:apply-templates>
not help to =(((
Firstly, you have an error in your XSLT
You can’t have an xsl:if within an xsl:apply-templates. You need a matching xsl:template and put the code in there…
In fact, you could do away with the xsl:if here, and just have the test in the template match
But to answer your question, you probably need to use the count attribute on the xsl:number element to count only the elements you want
Here is the full XSLT
When applied to you XML, the result is 123