Finding Nodes Relative to the Last Node in a Set

To obtain nodes relative to the last node in the set, use the position() and last() functions with arithmetic. For example, the following queries both obtain the last author element in the current context:

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

The following queries both return the next-to-last author element:

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

For information about position(), see Determining the Position Number of a Node. For information about last(), see Determining the Context Size.

 
Free Stylus Studio XML Training: