Abbreviated syntax for path expressions
XQuery provides an abbreviated syntax for expressing axes in path expressions.
Table 1 describes the abbreviations that are allowed in path expressions.
| Abbreviated syntax | Description |
|---|---|
| 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::. |
| @ | Shorthand abbreviation for attribute:: . |
| // | Shorthand abbreviation for 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 raises an error if the root node is not a document node. |
| .. | Shorthand abbreviation for parent::node(). |
Examples of abbreviated and unabbreviated syntax
Table 2 provides examples of abbreviated and unabbreviated syntax.
| Unabbreviated syntax | Abbreviated syntax | Result |
|---|---|---|
child::para |
para |
Selects the para elements
that are children of the context node. |
child::* |
* |
Selects all elements that are children of the context node. |
child::text() |
text() |
Selects all 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 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[attribute::type="warning"] |
para[@type="warning"] |
Selects all para children
of the context node that have a type attribute with the 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. |