position()

Probably the function most frequently used in XPointer predicates is position(). This returns the index of the node in the context node list. This allows you to find the first, second, third, or other indexed node. You can compare positions using the various relational operators like <, >, =, !=, >=, and <=.

For instance, in the family tree document, the root element is FAMILYTREE element is the root. It has 14 immediate children, 12 PERSON elements, and two FAMILY elements. In order, they are:

/child::FAMILYTREE/child::*[position()=1]
/child::FAMILYTREE/child::*[position()=2]
/child::FAMILYTREE/child::*[position()=3]
/child::FAMILYTREE/child::*[position()=4]
/child::FAMILYTREE/child::*[position()=5]
/child::FAMILYTREE/child::*[position()=6]
/child::FAMILYTREE/child::*[position()=7]
/child::FAMILYTREE/child::*[position()=8]
/child::FAMILYTREE/child::*[position()=9]
/child::FAMILYTREE/child::*[position()=10]
/child::FAMILYTREE/child::*[position()=11]
/child::FAMILYTREE/child::*[position()=12]
/child::FAMILYTREE/child::*[position()=13]
/child::FAMILYTREE/child::*[position()=14]


Previous | Next | Top | Cafe con Leche

Copyright 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified October 10, 1999