<?xml version="1.0"?> <a> <b/> <!-- this is the //b[count(./*)=0] --> <b> <!-- this is the //b[./c] --> <c/> </b> <b> <!-- this is the //b[3] --> <!-- and also //b[./c] --> <c/> </b> </a>
<?xml version="1.0"?> <a> <b/> <!-- this is the //b[count(./*)=0] --> <b> <!-- this is the //b[./c] --> <c/> </b> <b> <!-- this is the //b[3] --> <!-- and also //b[./c] --> <c/> </b> </a>
//b[3]
//b[./c]
//b[count(./*)=0]
<xsl:apply-templates match="para"/>
<xsl:value-of select="para/@id"/>
for $para in $doc//para
selects all para
in the document doc
let $mypara := $doc//para[@owner=myself]
where $para[@class=task]
order by $para/@created
Path describes (or "navigates" to) an XML document location. Paths syntax is constructed a similar way to paths in file systems, i.e.:
related to a context node (CN), see further, or
related to the root element but predicates are evaluated in relation to CN.
contains direct child nodes of CN
contains all descendants of CN except attributes.
contains the CN parent nod (if it exists)
contains all ancestors of CN - means parents, grandparents, etc to a root element (if the CN is not the root element itself)
contains all following siblings of CN (the axis is empty for NS and attributes)
dtto, but it contains the preceding sibling.
contains all nodes following the CN (except the attributes, child nodes and NS nodes)
dtto, but contains preceding nodes (except ancestors, attributes, NS)
contains attributes (for elements only)
contains all NS nodes of CN (for elements only)
the CN itself
contains the union of descendant and self axes
contains the union of ancestor and self axes
//b/child::*
<?xml version="1.0"?> <a> <b/> <b> <c/> <!-- this "c" will be selected --> </b> <b> <c/> <!-- and this "c" too --> </b> </a>
//b/descendant::*
<?xml version="1.0"?> <a> <b/> <b> <c> <!-- everything "under b" will be selected --> <d/> <!-- i.e. this "d" too --> </c> </b> <b> <c/> <!-- and this "c" too --> </b> </a>
//d/parent::*
<?xml version="1.0"?> <a> <b/> <b> <c> <!-- this "c" is the parent of "d" --> <d/> </c> </b> <b> <c/> </b> </a>
//d/ancestor::*
<?xml version="1.0"?> <a> <!-- this "a" is ancestor of "d" --> <b/> <b> <!-- this "b" is ancestor of "d" --> <c> <!-- this "c" is ancestor of "d" --> <d/> </c> </b> <b> <c/> </b> </a>
//b/following-sibling::*
<?xml version="1.0"?> <a> <b/> <!-- every child of "a" after this "b" is following-sibling --> <b> <!-- this "b" too --> <c> <d/> </c> </b> <b> <!-- this "b" too --> <c/> </b> </a>
//b/preceding-sibling::*
<?xml version="1.0"?> <a> <b/> <!-- this "b" too --> <b> <c> <d/> </c> </b> <!-- this "b" is preceding-sibling --> <b> <!-- every child of "a" before this "b" is preceding-sibling --> <c/> </b> </a>
/a/b/c/following::*
<?xml version="1.0"?> <a> <b/> <b> <c> <d/> </c> <!-- every element starting after "c" is following --> <e/> <!-- such as this "e" --> </b> <b> <!-- this "b" too --> <c/> <!-- this "c" too --> </b> </a>
/a/b/e/preceding::*
<?xml version="1.0"?> <a> <b/> <!-- this "b" too --> <b> <!-- this "b" too --> <c> <!-- this "c" too --> <d/> <!-- this "d" too --> </c> </b> <b> <d/> <!-- such as this "d" --> <e/> <!-- every element starting before "e" is preceding --> </b> </a>
/article/para[3]
— selects the 3rd paragraph (element para
) of
article (element article
)
preceding
.
ancestor
, preceding
, …) - position is
numbered always from the context node, means opposite to
document physical location directions.
position()=3
.
para
selects all child nodes of context node with name para
*
selects all element children of the context node
text()
selects all text node children of the context node
@name
selects the name
attribute of the context node
@*
selects all the attributes 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
*/para
selects all para
grandchildren of the context node
/doc/chapter[5]/section[2]
selects the second section
of the fifth chapter
of the doc
chapter//para
selects all descendants of element chapter
with name para
//para
selects all elements para
in the document
//olist/item
selects all elements item
with parent element olist
.//para
selects all descendant nodes of the context node with name para
..
selects the parent node of the context node
../@lang
selects a lang
attribute of the context node parent node
Most common used short notation is at child axis
child::article/child::para
.
para[@type="warning"]
instead of
child::para[attribute::type="warning"]
//
instead of
/descendant-or-self::node()/
.
and ..
For clarity, we keep sometimes the longer form: Do not fight it at all costs!
exist student/name="Fred"
, all student/@id