Abbreviated Syntax
An abbreviated syntax is available for particularly common location steps. In this syntax, five axes may use this shorthand:
- .
The context node
..The parent node
nameThe child element or elements with the specified name
//All descendants of the context node, and the context node itself
@nameThe attribute of the context node with the specified name
Using the abbreviated syntax, the previous examples can be rewritten in the following manner:
set
.//.
ancestor-or-self::*
@xlink:href
set[position( )=2]
.//.[.='Eunice']
ancestor-or-self::*[position( )=2][.="Celeste"]
@xlink:href[starts-with('http')]
ancestor-or-self::*/*[position( )=1]
document/set[position( )=2]/following-sibling::*
.//.[.='Eunice']/@ID
//ship/ancestor-or-self::*/*[position( )=1]
/document/set[position( )=2]/following-sibling::*
/descendant::node( )[.='Eunice']/@ID
set | ./*//vector | ancestor::* | @hrefNot all location steps can be rewritten using the abbreviated
syntax. In particular, only the child, self, attribute, descendant-or-self, and parent axes can be abbreviated. The
remaining axes must be spelled out in full.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access