XML technologies / XPath / XPath 2.0: language reference / XPath expressions: operators and keywords / Precedence of XPath operators

(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, chapter 4.)

Operators have a fixed natural evaluation order, called operator precedence. Parentheses around subexpressions and the operators combining them override this order. A parenthesized expression is evaluated first, regardless of the precedence of operators linking it to the rest of the expression.

The following table lists XPath operators and keywords used to combine or mark subexpressions, from top to bottom in decreasing precedence.

Operators/symbols

Meaning

[]

Predicates in path expressions

/, //

Path operators (path expressions)

(, )

Grouping subexpressions

except, intersect

Sequence difference and intersection

|, union

Sequence union

-$x

Unary minus

*, div, idiv, mod

Multiplicative operators

+, -

Additive operators

to

Range operator

=, !=, <, >, <=, >=,

eq, ne, lt, gt, le, ge, is, isnot

Comparison operators

cast as

Dynamic type conversion

castable as

Testing whether type conversion is possible

treat as

Static type assertion

instance of

Type test

and

Logical AND

or

Logical OR

if

Condition

some, every

Quantified operators

for

Iteration over an input sequence

,

Sequence concatenation

(:,  :)

Comment (start, end)

Table: operators and operator keywords in XPath 2.0.

Operator keywords must be written in lowercase as shown above. Operators consisting of two tokens (cast as, treat as, etc.) count as one operator and must be used in this form.

   

back to top