My Snippets

Position/index of an xml node

XML:
  1. <car>
  2. <wheel name="frontleft">...</wheel>
  3. <wheel name="frontright">...</wheel>
  4. <wheel name="backleft">...</wheel>
  5. <wheel name="backright">..</wheel>
  6. </car>

xpath:
count(//car/wheel[@name='backleft']/preceding-sibling::*) + 1
=> 3

February 10th, 2008 Posted by | xml | no comments
[]