Abbreviated syntax for path expressions

XQuery provides an abbreviated syntax for expressing axes in path expressions.

The following table describes the abbreviations that are allowed in path expressions.

Table 1. Abbreviated syntax for path expressions
Abbreviated syntax Description Examples
no axis specified Shorthand abbreviation for child:: except when the axis step specifies attribute() for the node test. When the axis step specifies an attribute test, an omitted axis is shorthand for attribute::. The path expression section/para is an abbreviation for child::section/child::para. The path expression section/attribute() is an abbreviation for child::section/attribute::attribute().
@ Shorthand abbreviation for attribute:: . The path expression section/@id is an abbreviation for child::section/attribute::id.
//

Shorthand abbreviation for /descendant-or-self::node()/, except when this abbreviation appears at the beginning of the path expression.

When this abbreviation appears at the beginning of the path expression, the axis step selects an initial node sequence that contains the root of the tree in which the context node is found, plus all nodes that are descended from this root. This expression returns an error if the root node is not a document node.

The path expression div1//para is an abbreviation for child::div1/descendant-or-self::node()/child::para .
.. Shorthand abbreviation for parent::node(). The path expression ../title is an abbreviation for parent::node()/child::title .

Examples of abbreviated syntax and unabbreviated syntax

The following table provides examples of abbreviated syntax and unabbreviated syntax.

Table 2. Unabbreviated syntax and abbreviated syntax
Unabbreviated syntax Abbreviated syntax Result
child::para para Selects the para elements that are children of the context node.
child::* * Selects all of the elements that are children of the context node.
child::text() text() Selects all of the text nodes that are children of the context node.
child::node() node() Selects all of the children of the context node. This expression returns no attribute nodes because attributes are not considered children of a node.
attribute::name @name Selects the name attribute of the context node
attribute::* @* Selects all of the attributes of the context node.
child::para[fn:position() = 1] para[1] Selects the first para element that is a child of the context node.
child::para[fn:position() = fn:last()] para[fn:last()] Selects the last para element that is a child of the context node.
/child::book/child::chapter[fn:position() = 5]
/child::section[fn:position() = 2]
/book/chapter[5]/section[2] Selects the second section of the fifth chapter of the book whose parent is the document node that contains the context node.
child::para[attribute::type="warning"] para[@type="warning"] Selects all para children of the context node that have a type attribute with the value warning.
child::para[attribute::type='warning']
[fn:position() = 5]
para[@type="warning"][5] Selects the fifth para child of the context node that has a type attribute with value warning.
child::para[fn:position() = 5]
[attribute::type="warning"]
para[5][@type="warning"] Selects the fifth para child of the context node if that child has a type attribute with value warning.
child::chapter[child::title='Introduction'] chapter[title="Introduction"] Selects the chapter children of the context node that have one or more title children whose typed value is equal to the string Introduction.
child::chapter[child::title] chapter[title] Selects the chapter children of the context node that have one or more title children.