XPath Abbreviations Quick Reference

Table 91 defines the abbreviations you can use in XPath expressions:

Abbreviation
Description
No axis is specified in a location step.

The child axis is assumed. For example, the following two XPath expressions both return the para children of chapter children of the context node:

chapter/para
               
child::chapter/child::para
               

            
@

The attribute axis. For example, the following two XPath expressions both return para children of the context node that have type attributes with a value of warning:

para[@type="warning"]
               
child::para[attribute::type="warning"]
               

            
//
The descendant-or-self axis. For example, the following two XPath expressions both return all para descendants of the context node:
//para
               
/descendant-or-self::node()/child::para
               

            
However, it is important to note that the following two expressions are not equivalent:
/descendant::para[1]
               
//para[1]
               

            
The first expression selects the first para element that is a descendant of the context node. The second expression selects each para descendant that is the first para child of its parent.
.
A single dot is the abbreviation for self::node(). This selects the context node. For example, the following two XPath expressions both return all para descendants of the context node:
.//para
               
self::node()/descendant-or-self::node()/child::para
               

            
..
A double dot is the abbreviation for parent::node(). This selects the parent of the context node. For example, the following two XPath expressions both return the title children of the parent of the context node:
../title
               
parent::node()/child::title
               

            
Table 91. XPath Abbreviations Quick Reference

Table 92 shows examples of abbreviations in XPath expressions

Example
Description
para
Selects the para children of the context node
*
Selects all element children of the context node
node_test
Evaluates all children of the context node and returns those that test true for the particular node_test
*/para
Selects all para grandchildren of the context node
para[1]
Selects the first para child of the context node
para[last()]
Selects the last para child of the context node
/doc/chapter[5]/section[2]
Selects the second section of the fifth chapter of the doc child of the context node
para[@type="warning"]
Selects para children of the context node that have type attributes with a value of warning
para[@type="warning"][5]
Selects the fifth para child of the context node that has a type attribute with a value of warning
para[5][@type="warning"]
Selects the fifth para child of the context node if that child has a type attribute with a value of warning
chapter[title]
Selects the chapter children of the context node that have one or more title children
//para
Selects all para descendants of the document root
chapter//para
Selects all para descendants of chapter children of the context node
//olist/item
Selects all item elements that have olist parents
.
Selects the context node
.//para
Selects the para descendants of the context node
..
Selects the parent of the context node
@*
Selects all attributes of the context node
@name
Selects the name attribute of the context node
../@name
Selects the name attribute of the parent of the context node
Table 92. Abbreviations in XPath Expressions

Airlines, Aerospace and Defense

Want to know what airlines, aerospace and defense companies are soaring high with Stylus Studio 2006? Well now you can! Come check out these leading companies and soar with Stylus Studio 2006 yourself.

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.

Learn Stylus Studio in 6 Minutes

Learn Stylus Studio in 6 Minutes is the world's fastest introduction to XML development using Stylus Studio. In just six minutes, learn how to leverage Stylus Studio's powerful XML tools and utilities to simplify XML development.

Learn XQuery in 10 Minutes, by Dr. Michael Kay - An XQuery Tutorial

Learn XQuery in 10 Minutes By Dr. Michael Kay is for all those people who really want to know what XQuery is, but don't have the time to find out. It's the fastest XQuery tutorial on the planet - read it now!

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member