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
name
The child element or elements with the specified name
//
All descendants of the context node, and the context node itself
@
name
The 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::* | @href
Not 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.
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.