XPath Abbreviations Quick Reference

Table 73 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 73. XPath Abbreviations Quick Reference

Table 74 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 74. Abbreviations in XPath Expressions

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!

XML Videos

Stylus Studio online XML video demonstrations illustrate how easy it is to learn advanced XML editing techniques. Now playing: Java Code Generation, Convert to XML, Grid View, and many other informative video demonstrations.

Industrial & Farm Equipment

Industrial & farm equipment manufacturers are mowing away the time it takes for data integration with the power of Stylus Studio 2006! See which top industrial and farm equipment manufacturers are cowboying up with Stylus Studio.

Stylus Studio API Documentation

Java API reference materials providing detailed information about Stylus Studio and other industry leading XML processing components.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member