XPath expression operators

An XPath expression returns either a node-set, a string, a Boolean, or a number.

The following operators are available for use with XPath expressions:

Addition operator
Format: +
Adds two numbers.
You can also use it to add two expressions that return a numeric result.
Minus operator
Format: -
Yields the difference between two numbers.
The minus (-) operator can also indicate the negative value of a numeric expression.
Multiply operator
Format: *
Multiplies two numbers.
Division Operator
Format: div
Divides two numbers and returns a floating decimal.
Mod Operator
Format: mod
Divides two numbers and returns only the remainder.
Equal Operator
Format: =
If the expression is equal to the specified value, the operator returns true. If the expression is not equal to the specified value, the operator returns false.
Example: price=7.80
Returns: True, if price is 7.80; false, if price is 7.90
Not equal to Operator
Format: !=
If the expression is not equal to the specified value, the operator returns true. If the expression is equal to the specified value, the operator returns false.
Example: price!=7.80
Returns: True if price is 7.90; false if price is 7.80
Less than Operator
Format: <
Compares two numeric expressions and determines whether expression1 is less than expression2; if so, the operator returns true. If expression1 is greater than or equal to expression2, the operator returns false.
Example: price<7.80
Returns: True if price is 7.00; false if price is 7.80
Less than or equal to Operator
Format: <=
Compares two specified numeric expressions and determines whether expression1 is less than or equal to the expression2; if it is, the operator returns true. If the expression1 is greater than expression2, the operator returns false.
Example: price<=7.80
Returns: True if price is 7.00; false if price is 7.90
Greater than Operator
Format: >
Compares two numeric expressions and determines whether expression1 is greater than expression2; if it is, the operator returns true. If expression1 is less than or equal to expression2, the operator returns false.
Example: price>7.80
Returns: True if price is 7.90; false if price is 7.80
Greater than or equal to Operator
Format: >=
Compares two numeric expressions and determines whether expression1 is greater than or equal to expression2 (true) or expression1 is less than expression2 (false).
Or Operator
Format: or
Logical or.
And Operator
Format: and
Logical and.
Parentheses operator
Format: ( )
Controls the order in which the operators execute in the expression. Parentheses override the normal precedence order and cause the expressions within the parentheses to be evaluated first. When parentheses are nested, the contents of the innermost parentheses are evaluated before the contents of the outer ones.
Boolean operator
Format: [ ]
A filter is evaluated as a Boolean on every node that is within the current context. If the Boolean evaluates to true, the node is included in the returned set; otherwise, it is excluded. Filters are enclosed in brackets.
Root operator
Format: /
Selects from the root node.
Anywhere operator
Format: //
Selects nodes in the document that match the selection no matter where they are.
Attribute operator
Format: @
Identifies an attribute of a node.