About Node Positions

The node positions for a node set start with 1. Evaluation of the position number is always based on document order. For example, the following query returns the first author element in the current context:

author[1] 
               

            

The next query finds the author elements (in the current context) that contain a first-name element. The query returns the third such author element.

(author[first-name])[position()=3] 
               

            

When you specify an integer in brackets, it is equivalent to calling the position() function. For example, the following queries both return the third y child element of each x child element in the current context:

x/y[3]
               
x/y[position()=3]
               

            

Tip: If you do not know the position of the node you want, a call to the position() function might help you. See Determining the Position Number of a Node.

The return value of the position() function depends on the specified axis. For example, suppose the axis is one of the reverse axes, such as preceding, ancestor, or preceding-sibling. The position() function returns the nth one in reverse document order that falls in the specified axis.

 
Free Stylus Studio XML Training:
W3C Member