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

[], ()

predicate, function call

/, //

path operator

!

simple mapping operator (XPath 3.0)

unary -, unary +

unary plus and minus

=>

arrow operator (XPath 3.1)

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.