Operators

Operators are special characters that has special meaning in a XPath expression.

/ Child

Selects the children of the current context. When used at the beginning of the expression, it starts from the root node.

/root/child 

// Recursive Descent

Searches the document, descending from the current context. When used at the beginning of the expression, it searches the entire document from the root node.

//span 

. Dot

Selects the current context. By default it takes the root node as the current context.

//td[.="foo"]

.. Double dot

Selects the parent of the current context.

/table/tr/td/..

* Wildcard

Selecta all nodes from the current context.

/table/tr/td/table/*/td

@ Attribute

Selects the node with the attribute and returns the attribute.

//div/@style

@* Attribute wildcard

Selects nodes with any attributes and returns the attributes.

//@*

() Round brackets

Expressions within round brackets takes precedence in the evaluation order

(//@*)[1]

Square brackets

Used both as a subscript operator and to encapsulate a filter expression.

(//td)[2]

Arithmetic

Basic arithmetic operations such as addition, subtraction, multiplication, devision and modulo are available.

count(//td) + count(//table)