Operators

The various operators for composing expressions (in XPath 2.0, 3.0, 3.1 and 4.0) are described, in roughly the order of precedence (as described in the table at below), in the sections that follow.

Parentheses and operator precedence

In general an expression may be enclosed in parentheses without changing its meaning.

If parentheses are not used, operator precedence follows the sequence below, starting with the operators that bind most tightly. Within each group the operators are evaluated left-to-right.

Operator

Meaning

XPath version

More information

unary ?

unary lookup operator

3.1

Lookup expressions

[]

predicate

2.0

Filter expressions

binary ?

binary lookup operator

3.1

Lookup expressions

()

function call

2.0

Function calls

/, //

path operator

2.0

Path expressions

!

simple map operator

3.0

Simple mapping expressions

unary -, unary +

unary plus and minus

2.0

Arithmetic expressions

=?>

method call operator

4.0

Lookup expressions

=>, =!>

arrow operator, mapping arrow operator

3.1, 4.0

Arrow expressions

->

pipeline operator

4.0

Pipeline expressions

cast as

dynamic type conversion

2.0

Cast as, Treat as

castable as

type test

2.0

Instance of and Castable as

treat as

static type conversion

2.0

Cast as, Treat as

instance of

type test

2.0

Instance of and Castable as

intersect, except

set difference and intersection

2.0

Set difference and intersection

|, union

union operation on sets

2.0

Union

*, div, idiv, mod

multiply, divide, integer divide, modulo

2.0

Arithmetic expressions

+, -

plus, minus

2.0

Arithmetic expressions

to

range expression

2.0

Range expressions

||

string concatenation

3.0

String concatenation

otherwise

otherwise expression

4.0

Otherwise operator

=, !=, <, <=, >, >=, eq, ne, lt, le, gt, ge

comparisons

2.0

Comparisons

is, is-not, <<, >>, precedes-or-is, follows-or-is, precedes, follows

node comparisons

4.0

Comparisons

and

Boolean and

2.0

Logical operators

or

Boolean or

2.0

Logical operators

if

conditional expressions

2.0

Conditional expressions

some, every

quantified expressions

2.0

Quantified expressions

let

variable declaration

3.0

Let expressions

for

iteration (mapping) over a sequence

2.0

For expressions

, (comma)

Sequence concatenation

2.0

Sequence expressions