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.


E Error Conditions

err:XPST0001

It is a static error if analysis of an expression relies on some component of the static context that is absentDM.

err:XPDY0002

It is a type error if evaluation of an expression relies on some part of the dynamic context that is absentDM.

Note:

In version 4.0 this has been reclassified as a type error rather than a dynamic error. This change allows a processor to report the error during static analysis where possible; for example if the body of a user-defined function is written as fn($x) { @code }. The error code is prefixed XPDY rather than XPTY for backwards compatibility reasons.

err:XPST0003

It is a static error if an expression is not a valid instance of the grammar defined in A.1 EBNF.

err:XPTY0004

It is a type error if, during the static analysis phase, an expression is found to have a static type that is not appropriate for the context in which the expression occurs, or during the dynamic evaluation phase, the dynamic type of a value does not match a required type as specified by the matching rules in 3.1.2 Sequence Type Matching.

err:XPTY0006

During the analysis phase, an expression is classified as implausible if the inferred static typeS and the required type R are substantively disjoint; more specifically, if neither of the types is a subtype of the other, and if the only values that are instances of both types are one or more of: the empty sequence, the empty map, and the empty array.

err:XPST0008

It is a static error if an expression refers to an element name, attribute name, schema type name, or variable name that is not defined in the static context, except for an ElementName in an ElementTest or an AttributeName in an AttributeTest.

err:XPST0010

An implementation that does not support the namespace axis must raise a static error if it encounters a reference to the namespace axis and XPath 1.0 compatibility mode is false.

err:XPST0017

It is a static error if the expanded QName and number of arguments in a static function call do not match the name and arity range of a function definition in the static context, or if an argument keyword in the function call does not match a parameter name in that function definition, or if two arguments in the function call bind to the same parameter in the function definition.

err:XPTY0018

It is a type error if the result of a path operator contains both nodes and non-nodes.

err:XPTY0019

It is a type error if E1 in a path expression E1/E2 does not evaluate to a sequence of nodes.

err:XPTY0020

It is a type error if, in an axis step, the context item is not a node.

err:XPST0021

It is a static error if two fields in a record declaration have the same name.

err:XPST0023

It is a static error if a recursive record type cannot be instantiated (typically because it contains a self-reference that is neither optional nor emptiable). Processors are not required to detect this error.

err:XQST0039

It is a static error for an inline function expression to have more than one parameter with the same name.

err:XQST0046

An implementation MAY raise a static error if the value of a BracedURILiteral is of nonzero length and is neither an absolute URI nor a relative URI.

err:XPDY0050

It is a dynamic error if the dynamic type of the operand of a treat expression does not match the sequence type designated by the treat expression. This error might also be raised by a path expression beginning with / or // if the context node is not in a tree that is rooted at a document node. This is because a leading / or // in a path expression is an abbreviation for an initial step that includes the clause treat as document-node().

err:XPST0051

It is a static error if an expanded QName used as an ItemType in a is not defined in the static context either as a named item type in the in-scope named item types, or as a generalized atomic type in the in-scope schema type.

err:XQST0052

The type named in a cast or castable expression must be the name of a type defined in the in-scope schema types, and the type must be simple.

err:XQST0070

A static error is raised if any of the following conditions is statically detected in any expression:

  • The prefix xml is bound to some namespace URI other than http://www.w3.org/XML/1998/namespace.

  • A prefix other than xml is bound to the namespace URI http://www.w3.org/XML/1998/namespace.

  • The prefix xmlns is bound to any namespace URI.

  • A prefix other than xmlns is bound to the namespace URI http://www.w3.org/2000/xmlns/.

err:XPST0080

It is a static error if the target type of a cast or castable expression is xs:NOTATION, xs:anySimpleType, or xs:anyAtomicType.

err:XPST0081

It is a static error if a QName used in an expression contains a namespace prefix that cannot be expanded into a namespace URI by using the statically known namespaces.

err:XQST0089

It is a static error if a variable bound in a for expression, and its associated positional variable, do not have distinct names (expanded QNames).

err:XPST0107

It is a static error if the annotation %method is used on a focus function.

err:XPTY0117

When applying the coercion rules, if an item is of type xs:untypedAtomic and the expected type is namespace-sensitive, a type error [err:XPTY0117] is raised.

err:XPDY0130

An implementation-dependent limit has been exceeded.

err:XQST0134

The namespace axis is not supported.

err:XQDY0137

No two keys in a map may have the same key value.

err:XQST0140

It is a static error if a named item type declaration is recursive, unless it satisfies the conditions defined in 3.2.8.3.1 Recursive Record Types.

err:XPTY0141

In a forexpression, when the keyword member is present, the value of the binding collection must be a single array; and when either or both of the keywords key and value are present, the value of the binding collection must be a single map.

err:XPTY0144

During the analysis phase, an axis step is classified as implausible if the combination of the inferred context item type, the choice of axis, and the supplied node test, is such that the axis step will always return an empty sequence.

err:XPTY0145

During the analysis phase, a unary or postfix lookup expression is classified as implausible if the combination of the inferred type of the left-hand operand (or the context item type in the case of a unary expression) and the choice of key specifier is such that the lookup expression will always return an empty sequence.

err:XPST0152

It is a static error if a key type named in a is not a generalized atomic type.