mfran2002 Posted January 28, 2010 Share Posted January 28, 2010 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 More sharing options...
boen_robot Posted January 29, 2010 Share Posted January 29, 2010 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 More sharing options...
Martin Honnen Posted January 29, 2010 Share Posted January 29, 2010 /roottag/tagchild[not(@type = 'skip')][1] gives you the first such element you are looking for, then you can count the preceding-sibling tagchild elements and add 1 e.g. count(/roottag/tagchild[not(@type = 'skip')][1]/preceding-sibling::tagchild) + 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.