Jump to content

Xsl While Loop


mfran2002

Recommended Posts

hello,I have this xml input file:<roottag><tagchild type="skip">valuex</tagchild><tagchild type="skip">valuey</tagchild><tagchild type="text">value1</tagchild><tagchild type="text">value2</tagchild><tagchild type="skip">valuez</tagchild><tagchild type="text">value3</tagchild><tagchild type="text">value4</tagchild><tagchild type="skip">valuew</tagchild><tagchild type="text">value5</tagchild><tagchild type="text">value6</tagchild></roottag>I need the index of the first tagchild with type!=skip...in the example above index=3do you know how can I do?thanks

Link to comment
Share on other sites

I think

<xsl:value-of select="//tagchild[@type != 'skip'][1]/position()" />

should produce what you need.If it doesn't, you may have to manually loop over all tagchild elements, check the attribute, then get the position if it matches, like so:

<xsl:for-each select="//tagchild"><xsl:if test="@type != 'skip'"><xsl:value-of select="position()" /></xsl:if></xsl:for-each>

In this case, if you need to actually do something more with the result, than just output it (which seems likely), you'll have to pass the position() as a parameter to another template. THAT template should then do whatever it has to do with the position in mind.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...