View Old View New View Both View Only Previous Next

This draft contains only sections that have differences from the version that it modified.

W3C

XML Path Language (XPath) 4.0 WG Review Draft

W3C Editor's Draft 23 February 2026

This version:
https://qt4cg.org/specifications/xpath-40/
Most recent version of XPath:
https://qt4cg.org/specifications/xpath-40/
Most recent Recommendation of XPath:
https://www.w3.org/TR/2017/REC-xpath-31-20170321/
Editor:
Michael Kay, Saxonica <mike@saxonica.com>

Please check the errata for any errors or issues reported since publication.

See also translations.

This document is also available in these non-normative formats: XML.


Abstract

XPath 4.0 is an expression language that allows the processing of values conforming to the data model defined in [XQuery and XPath Data Model (XDM) 4.0]. The name of the language derives from its most distinctive feature, the path expression, which provides a means of hierarchic addressing of the nodes in an XML tree. As well as modeling the tree structure of XML, the data model also includes atomic items, function items, maps, arrays, and sequences. This version of XPath supports JSON as well as XML, and adds many new functions in [XQuery and XPath Functions and Operators 4.0].

XPath 4.0 is a superset of XPath 3.1. A detailed list of changes made since XPath 3.1 can be found in I Change Log.

Status of this Document

This is a draft prepared by the QT4CG (officially registered in W3C as the XSLT Extensions Community Group). Comments are invited.

Dedication

The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).

Michael was central to the development of XML and many related technologies. He brought a polymathic breadth of knowledge and experience to everything he did. This, combined with his indefatigable curiosity and appetite for learning, made him an invaluable contributor to our project, along with many others. We have lost a brilliant thinker, a patient teacher, and a loyal friend.


A XPath 4.0 Grammar

A.5 Precedence Order (Non-Normative)

The grammar in A.1 EBNF normatively defines built-in precedence among the operators of XPath. These operators are summarized here to make clear the order of their precedence from lowest to highest. The associativity column indicates the order in which operators of equal precedence in an expression are applied (further details below).

#OperatorAssociativity
1, (comma)eitherassociative
2for,let,some, every, ifNA
3oreitherassociative
4andeitherassociative
5eq, ne, lt, le, gt, ge, =, !=, <, <=, >, >=, is, <<, >>NA
6otherwiseeitherassociative
7||left-to-rightassociative
8toNA
9+, - (binary)left-to-right
10*, div, idiv, modleft-to-right
11union, |eitherassociative
12intersect, exceptleft-to-right
13instance ofNA
14treat asNA
15castable asNA
16cast asNA
17=>, =!>left-to-right
18-, + (unary)right-to-left
19!left-to-right
20/, //left-to-right
21a[ b], a?[b], a?b, a??b, a(b)left-to-right
22? (unary)NA

In the "Associativity" column, "either" indicates that all the operators at that level have the associative property (i.e., (A op B) op C is equivalent to A op (B op C)), so their associativity is inconsequential. "NA" (not applicable) indicates that the EBNF does not allow an expression that directly contains multiple operators from that precedence level, so the question of their associativity does not arise.

Entries in the Associativity column have the following meaning (where the symbol represents any operator):

  • associative means that the order of evaluation is immaterial: for example a, b, c can be evaluated either as (a, b), c or as a, (b, c), producing the same result either way.

  • NA indicates that it is not possible to write an expression of the form a ⊙ b ⊙ c for this particular operator: for example, the grammar does not allow a = b = c.

  • left-to-right means that for expressions using these operators, a ⊙ b ⊙ c is evaluated as (a ⊙ b) ⊙ c. As a special case, the operators + and * are associative provided they are not mixed with other operators of the same precedence.

  • right-to-left is used only for unary operators, and indicates that ⊙ ⊙ a is evaluated as ⊙ (⊙ a)

These rules do not constrain the order in which the operands of an expression are evaluated (which might affect error behavior). See also 2.4 Error Handling.

Note:

Parentheses can be used to override the operator precedence in the usual way. Square brackets in an expression such as A[B]A?[B]or serve two roles: they act as an operator causing B to be evaluated once for each item in the value of A, and they act as parentheses enclosing the expression B.