Specifications
selects the parent of the context node
../@lang
selects the lang attribute of the parent of the context node
para[@type="warning"]
selects all para child elements of the context node that have a type attribute with value warning
para[@type="warning"][5]
selects the fifth para child element of the context node that has a type attribute with value
warning
para[5][@type="warning"]
selects the fifth para child element of the context node if that child has a type attribute with
value warning
chapter[title="Introduction"]
selects the chapter child elements of the context node that have one or more title child elements
with string-value equal to Introduction
//field[name="JobID"]/value
selects all value elements in the document that have a parent field element and a sibling name
element with string-value equal to JobID
chapter[title]
selects the chapter child elements of the context node that have one or more title child elements
employee[@secretary and @assistant]
selects all the employee child elements of the context node that have both a secretary attribute
and an assistant attribute
Expressions
The location paths listed in the previous section contain a few examples of simple expressions
used to filter nodes (such as @type="warning" to filter out elements with a particular attribute
value). Expressions can also stand on their own, and can be used to express calculations based
on the result of a location path. XPath provides a limited number of functions for use in
expressions.
Here are some examples of expressions:
para
evaluates to the text contents of the para element(s)
@type
evaluates to the text contents of the type attribute
(2 + 3) * 4
evaluates to the number 20
number(@type) > 10
evaluates to true if the contents of the type attribute represents a number that is greater than
10; and to false otherwise
count(//field)
329
Enfocus Switch 10