For-Each - counting found nodes and not all nodes

This should cover W3C XML Schema, Relax NG and DTD related problems.
tlewis
Posts: 1

For-Each - counting found nodes and not all nodes

Fri Apr 17, 2009 11:38 pm

O.K. here is my issue.
First the XML (or a snippet)

<photos>
<image>
<ImagePath>Portraits</ImagePath>
<!-- some more stuff --->
</image>
<image>
<ImagePath>Black-White</ImagePath>
<!-- some more stuff --->
</image>
<image>
<ImagePath>Portraits</ImagePath>
<!-- some more stuff --->
</image>
</photos>

<xsl:for-each select="photos/image">
<xsl:if test="contains(ImagePath,$smode)">
<!----- do some stuff --- >
</xsl:if>
</xsl:for-each>

What I am trying to achieve is to index each item starting at 1 to the total items found. So, looking at the above example, if I did a For-Each for portraits then I would expect the output to be:
1 Portraits
2 Portraits

But the result was:
1 Protraits
3 Portraits

Reading up on how the For-each works indicates the above is correct.
The XML <ImagePath> can contain any path and not in any order, so using Count or Count(preceding:: does not give me the results I require.
Is there any way that I can create an index from 1 to .... as I have now spent far too long reading, searching the net and slowly going blind. :D

Tony

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 3 guests