Finding the First Node That Meets a Condition

Suppose you want to obtain from a collection the first node that meets a certain condition. For example, you want the first book whose author's last name is Bob. You can specify the following query:

(//book[author/last-name="Bob"])[position()=1]
               

            

When the XPath processor evaluates this expression, it creates a collection of book elements where the author's last name is Bob. The XPath processor then returns the first node in this collection.

The following two expressions appear to also return the first book whose author's last name is Bob, but they do not. Instead, these queries both return a book whose author's last name is Bob only if that book is the first book in the document.

//book[author/first-name="Bob"][position()=1]
               
//book[author/first-name="Bob" and position() = 1]
               

            

XSLT Debugger

Stylus Studio's XSLT debugger - a requirement for building bug-free XSLT stylesheets and XML data transformation applications. Stylus Studio's XSLT debugger gives you complete visibility and control over the XSLT transformation process.

Chemical Companies That Use Stylus Studio

When working in a lab it's always important to have the right ingredients. That's why top chemical companies use Stylus Studio 2006 to create the ultimate experiments. See which of these top chemical companies are using Stylus Studio today!

XML Programming

Simplify XML Programming with Stylus Studio's XML Pipeline, a powerful tool for modeling, programming, debugging and deploying complete XML programs.

ETL - Extract, Transform, Load

Designing Extract, Load and Tranform (ETL) applications including ETL data warehousing, etl design and etl programming is easy with Stylus Studio's XML and ETL Tools. Start ETL Programming today.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member