count with xpath
Posted: Thu Mar 02, 2006 5:53 pm
Hi, I have a problem with counting some Xml Elements.
I have an element in the xml structure, which occurs at different positions and different levels. How can I count this element without always starting at a new number, when it occurs in a different Tag
My structure is something like this:
<a>
<b>
<tocount/>
</b>
<b>
<b>
<tocount/>
</b>
<c>
<tocount/>
<c>
</b>
</a>
In my Xslt stylesheet I want get the number of the element, when I match it:
<xsl:template match="tocount">
<xsl:number count='//tocount'/>
</xsl:template>
The result for each element should be an increasing number
<a><b>
1
</b>
<b>
<b>
2
</b>
<c>
3
<c>
</b>
</a>
Thanks for help,
Kirstin
I have an element in the xml structure, which occurs at different positions and different levels. How can I count this element without always starting at a new number, when it occurs in a different Tag
My structure is something like this:
<a>
<b>
<tocount/>
</b>
<b>
<b>
<tocount/>
</b>
<c>
<tocount/>
<c>
</b>
</a>
In my Xslt stylesheet I want get the number of the element, when I match it:
<xsl:template match="tocount">
<xsl:number count='//tocount'/>
</xsl:template>
The result for each element should be an increasing number
<a><b>
1
</b>
<b>
<b>
2
</b>
<c>
3
<c>
</b>
</a>
Thanks for help,
Kirstin