Examples of Specifying Positions

The following query finds the first and fourth author elements:

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


The next query finds the first, the third through the fifth, and the last author elements:

author [(position() = 1) or 

(position() >= 3 and position() <= 5) or 
(position() = last())]


The XPath processor removes duplicate values. For the previous query, if there are only five elements in the collection, the query returns only one copy of the fifth element.

The next example finds all author elements in which the first degree is a Ph.D.:

author[degree[1] = "Ph.D."] 


Free Stylus Studio XML Training:
W3C Member