Finding Multiple Nodes

To obtain several nodes in one operation, use the and or the or operator with the position() and last() functions. For example, the following query returns the first and the last author nodes in the current context:

author [(position() = 1) or (position() = last())]
               

            

You can also specify a range of nodes. For example, the next query returns the second, third, and fourth author elements:

author [(position() >= 2) and ( position() <= 4)]
               

            

To obtain a range of nodes, m to n, relative to the last node, use the following format:

(m <= position()) and (position() <= n )

For example, the following query obtains the last five nodes in the current context:

author [(last() - 4) <= position()) and (position() <= last())]
               

            

 
Free Stylus Studio XML Training:
W3C Member