Determining the Position Number of a Node

The position() function returns an integer that indicates the position of the node within the parent. Positions start with 1; a node with a position of 1 is always the first node in the collection.

For example, the following query returns the first three degree elements in the document:

(//degree)[position() < 4] 
               

            

The next query finds the first two book children in the current context:

book[position() <= 2] 
               

            

The XPath processor executes the position() function with respect to the parent node. Consider the following data:

<x>
               

              
<y/>
                   
<y/>
                   

                
</x> <x>
<y/>
                   
<y/>
                   

                
</x>

The following expression returns the first y element contained in each x element:

x/y[position() = 1] 
               

            

For more information, see also Finding an Element with a Particular ID.

Internet & eBusiness

Internet & eBusiness

ADO to XML

The Stylus Studio ADO to XML data coversion wizard simplifies extracting of relational data into any XML format.

DTD Parser

Learn about the powerful DTD parser technologies that are supported in Stylus Studio's DTD tools, including DOM and SAX based DTD parsing components.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member