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.

JSP Editor

Edit and Validate JSP 1.2 and JSP 2.0 documents. Includes JSP syntax coloring, JSP code completion and more.

Scientific, Photo & Control Equipment

Scientific, photo & control equipment companies hear clicks and beeps all day. But, when it comes to data integration it needs to be done in a flash, that's why they use Stylus Studio. Come see which top companies are seeing XML in a brand new light!

XML-to-HTML Mapper

Stylus Studio simplifies XML-to-HTML mapping through the industry's first and only XML to HTML mapping tool based on industry standard XSLT.

Multi Channel Publishing

Multi channel publishing lets you go beyond single-source publishing of HTML and PDF to also generate simultaneously for non-document forms, such as to communicate with partners or drive spreadsheets.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member