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

unary ?

unary lookup operator

[], (), binary ?

predicate, function call, lookup operator

/, //

path operator

!

simple mapping operator

unary -, unary +

unary plus and minus

=>

arrow operator

cast as

dynamic type conversion

castable as

type test

treat as

static type conversion

instance of

type test

except, intersect

set difference and intersection

|, union

union operation on sets

*, div, idiv, mod

multiply, divide, integer divide, modulo

+, -

plus, minus

to

range expression

||

string concatenation (XPath 3.0)

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

comparisons

and

Boolean and

or

Boolean or

if

conditional expressions

some, every

quantified expressions

let

variable declaration (XPath 3.0)

for

iteration (mapping) over a sequence

, (comma)

Sequence concatenation

The various operators are described, in roughly the above order, in the sections that follow.