Here are some examples of location paths using abbreviated syntax:
-
para
selects thepara
element children of the context node -
*
selects all element children of the context node -
text()
selects all text node children of the context node -
@name
selects thename
attribute of the context node -
@*
selects all the attributes of the context node -
para[1]
selects the firstpara
child of the context node -
para[last()]
selects the lastpara
child of the context node -
*/para
selects allpara
grandchildren of the context node -
/doc/chapter[5]/section[2]
selects the secondsection
of the fifthchapter
of thedoc
-
chapter//para
selects thepara
element descendants of thechapter
element children of the context node -
//para
selects all thepara
descendants of the document root and thus selects allpara
elements in the same document as the context node -
//olist/item
selects all theitem
elements in the same document as the context node that have anolist
parent -
.
selects the context node -
.//para
selects thepara
element descendants of the context node -
..
selects the parent of the context node -
../@lang
selects thelang
attribute of the parent of the context node -
para[@type="warning"]
selects allpara
children of the context node that have atype
attribute with valuewarning
-
para[@type="warning"][5]
selects the fifthpara
child of the context node that has atype
attribute with valuewarning
-
para[5][@type="warning"]
selects the fifthpara
child of the context node if that child has atype
attribute with valuewarning
-
chapter[title="Introduction"]
selects thechapter
children of the context node that have one or moretitle
children with string-value equal toIntroduction
-
chapter[title]
selects thechapter
children of the context node that have one or moretitle
children -
employee[@secretary and @assistant]
selects all theemployee
children of the context node that have both asecretary
attribute and anassistant
attribute