Queries That Return More Than You Want

Suppose you want the titles of all the books. You might decide to define your query like this:

//title
               

            

This query does return all titles of books, but it also returns the title of a magazine. This query instructs the XPath processor to start at the root node, search all descendants, and return all title elements. In bookstore.xml, this means that the query returns the title of the magazine in addition to the titles of books. In some other document, if all titles are contained in book elements, this query returns exactly what you want.

To query and obtain only the titles of books, you can use either of the following queries. They obtain identical results. However, the first query runs faster.

/bookstore/book/title
               
//book/title
               
 
               

            

The first query runs faster because it uses the child axis, while the second query uses the descendent-or-self axis. In general, the simpler axes, such as child, self, parent, and ancestor, are faster than the more complicated axes, such as descendent, preceding, following, preceding-sibling, and following-sibling. This is especially true for large documents. Whenever possible, use a simpler axis.

Saxon XSLT Processor

Stylus Studio® has partnered with Saxonica, a leading provider of Java-based XSLT and XQuery processing components to offer a robust XSLT 1.0 and 2.0 development environment, featuring development and deployment using the Saxon XSLT processor.

Open XSLT Architecture

Learn how Stylus Studio's Open XSLT Architecture enables you to use any of the popular industry-standard XSLT processors (like Saxon, Xalan-J, MSXML, Microsoft .NET, and others) for all your XSLT development tasks.

XML Syntax Help - Intelligent XML Editing

Stylus Studio's XML Editors feature Intelligent XML Schema/DTD-Aware Code Sensing and context sensitive XML code auto-completion. Simplify XML editing with Stylus Studio today.

Text File to XML

Stylus Studio provides several easy-to-use document wizards that allow you to quickly convert text files to XML. Create XML from text and EDI, create XML Schema from EDIFACT, and more!

Stylus Most Wanted

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.