XPath expression wizard - Syntax Reference options

You can use the Syntax Reference options in the XPath expression wizard to specify a location path and operators for your XPath expression.

To access the Syntax Reference options, click the Reference tab in the XPath expression wizard.

A location path describes the location of a node or a group of nodes in an XML document. There are two different kind of location paths - absolute and relative. Absolute paths begin at a fixed reference point - the root node. Relative paths begin at a variable point - a context node.

A location path returns a node set, which is a collection of nodes (any part of an XML document, such an element, attribute, namespace, or comment). Location paths consist of location steps. Each step has two parts:

A location step looks like this:

axis: node-test

Location steps can be combined by separating them with forward slashes. Each step in the resulting location path sets the context node for the next path in the step.

Operators are used to manipulate numeric values, combine paths, and compare string or numeric values.

 

Axis specifiers

Each XPath location step moves along an axis from a context node. For example, if you select child as your axis, your XPath expression searches through all the children of the context node.

Axis Location in which nodes are searched for
ancestor:: The root node and all element nodes that contain the context node.
ancestor-or-self :: All ancestors of the context node, as well as the node itself.
attribute:: All attributes of the context node.
child:: All children of the context node. Attribute and namespace nodes are not children of any nodes, although they do have parent nodes.

This is the default value.

descendant:: All nodes contained inside the context node, that is, any children or children of children and so on. Only root and element nodes have descendants. Like the child axis, the descendant axis never contains attributes or namespace nodes.
descendant-or-self:: Any descendent of the context node or the context node itself.
following:: All nodes that begin after the context node ends, except for attribute nodes and namespace nodes.
following-sibling:: All nodes that follow the end of the context node and have the same parent node. Attributes and namespace nodes do not have siblings.
namespace:: All namespaces in scope on the context node.
parent:: The element or root node that immediately contains the context node. Only the root node does not have a parent node.
preceding:: All nodes that end before the context node begins, except for attribute nodes and namespace nodes.
preceding-sibling:: All nodes that precede the start of the context node and have the same parent node. Attributes and namespace nodes do not have siblings.
self:: The context node itself.

 

Node tests

Each location step has at least an axis and a node test. The node test further refines the nodes selected by the location step. For example, if you specify child:: comment( ) as your location step, your XPath expression returns all the comment node children of the context node.

Node What it returns
* Selects all elements, regardless of name. For example, child::* selects all element children of the context node, and attribute::* selects all attributes of the context node.
comment ( ) All comment nodes.
node( ) All nodes, regardless of type.
processing-instruction ('target' ) With no arguments, it returns all processing instructions. With a single string argument target, it selects all processing instructions that have the specified target.
text( ) All text nodes. For example, child::text() selects all the text node children of the context node.

 

Operators

There are three different kinds of operators:

Node Set

Operator Function
| This is the union operator. It takes two node sets and combines all the nodes in the node sets together (after removing duplicate nodes).
/ Selects all the child nodes.
// Selects the descendant nodes.

Boolean

Boolean operators can be used to compare string or numeric expressions or Boolean values.

Operator Returns
<= true if the value of the first numeric expression is less than or equal to the value of the second, otherwise false.
< true if the value of the first numeric expression is less than the value of the second, otherwise false.
>= true if the value of the first numeric expression is greater than or equal to the value of the second, otherwise false.
> true if the value of the first numeric expression is greater than the value of the second, otherwise false.
= True if both expressions (string or numeric) have the same value, otherwise false.
!= true if both expressions (string or numeric) do not have the same value, otherwise false.
and True if both Boolean values are true, otherwise false.
or Ffalse only if both values are false, otherwise true.

Number

These operators can be used to manipulate numeric values.

Operator Returns
+ The sum of two number expressions.
- The difference of the first numeric expression minus the second.
* The product of two numeric expressions.
div The first numeric expression divided by the second expression.
mod \ The first numeric expression modulo the second expression (returns the remainder).

 

Parent topic

Creating XPath expressions

 

Related concepts

XPath expression wizard

Related reference
XPath expression wizard - Functions Reference options