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.

Support for US National Library of Medicine (NLM) Document Type Definitions

Stylus Studio provides support for editing and validating XML documents using US National Library of Medicine data models. In this tutorial, we'll provide a step-by-step overview of how to use the NLM DTD's in Stylus Studio!

Medical Companies That Use Stylus Studio

Medical companies can't solve every ache and pain. That's why when it comes to the struggle of data integration, they turn to Stylus Studio to simplify their pains. Come see which medical companies are injecting Stylus Studio into their work load!

Why XQuery - The Case for XQuery

Read "The Case for XQuery" - an article that debuted in the November 2005 issue of SOA WebServices Journal, written by Jerry King, Vice President of DataDirect Technologies.

Export HTML to XML

Export HTML to XML with the click of a button - simplify migration of legacy HTML code to industry standard XML technologies with Stylus Studio.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member