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

XQuery 4.0: An XML Query Language

W3C Editor's Draft 23 February 2026

This version:
https://qt4cg.org/specifications/xquery-40/
Most recent version of XQuery:
https://qt4cg.org/specifications/xquery-40/
Most recent Recommendation of XQuery:
https://www.w3.org/TR/2017/REC-xquery-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

XML is a versatile markup language, capable of labeling the information content of diverse data sources, including structured and semi-structured documents, relational databases, and object repositories. A query language that uses the structure of XML intelligently can express queries across all these kinds of data, whether physically stored in XML or viewed as XML via middleware. This specification describes a query language called XQuery, which is designed to be broadly applicable across many types of XML data sources.

A list of changes made since XQuery 3.1 can be found in J 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).


I Backwards Compatibility (Non-Normative)

I.1 Incompatibilities relative to XQuery 3.1

In fn:format-integer, certain formatting pictures using a circumflex as a grouping separator might be interpreted differently in 4.0: for example format-integer(1234, "9^999") would output "1^234" in 3.1, but will output "1621" (1234 in base 9) with 4.0. As a workaround, this can be rewritten as format-integer(1234, "0^000").

In computed node constructors, the node name must now be written in quotation marksas a QName literal (with a preceding # character) if it matches certain language keywords. For example element div {} must now be written element "#div" {}. (Alternatively, element { "div" } {} and element Q{}div {} are permitted by both XQuery 3.1 and XQuery 4.0.) This change is made because {} is now a valid expression representing an empty map, so expressions such as element otherwise {} could (without this rule) be parsed in two different ways.

In XQuery 4.0, certain expressions are classified as implausible: an example is @code/text(), which will always return an empty sequence. A processor may report a static error when such expressions are encountered; however, processors are required to provide a mode of operation in which such expressions are accepted, thus retaining backwards compatibility.

In expressions that deliver a function item, notably partial function applications, named function references, and the fn:function-lookup function, errors may now be detected at the point where the function item is created when they were previously detected at the point where the function item was called. This was underspecified in previous versions. For example, the partial function application contains(?, 42) is now required to raise a type error (because the second argument should be a string, not an integer) at the point where the partial function application occurs, not at the point where the resulting function is called.

As explained in 3.4.3 Function Coercion, the fact that coercion rules are now applied to global variables and local variable bindings introduces an incompatibility in the case of variables whose value is a function item. Previously it was possible to supply a function item that accepted a wider range of argument values than those declared in the variable's type declaration; this is no longer the case.