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 and XPath Data Model 4.0

W3C Editor's Draft 23 February 2026

This version:
https://www.w3.org/TR/2000/REC-xpath-datamodel-40-20000101/
Latest version of XQuery and XPath Data Model 4.0:
https://www.w3.org/TR/xpath-datamodel-40/
Previous versions of XQuery and XPath Data Model 4.0:
https://www.w3.org/TR/2017/PR-xpath-datamodel-31-20170117/
https://www.w3.org/TR/2016/CR-xpath-datamodel-31-20161213/
https://www.w3.org/TR/2014/CR-xpath-datamodel-31-20141218/
Most recent version of XQuery and XPath Data Model 4:
https://www.w3.org/TR/xpath-datamodel-4/
Most recent version of XQuery and XPath Data Model:
https://www.w3.org/TR/xpath-datamodel/
Most recent Recommendation of XQuery and XPath Data Model:
https://www.w3.org/TR/2014/REC-xpath-datamodel-30-20140408/
Editors:
Norm Tovey-Walsh, Saxonica, Ltd <norm@saxonica.com>
John Snelson (XML Query WG), MarkLogic Corporation <john.snelson@marklogic.com>
Andrew Coleman (XML Query WG), IBM Hursley Laboratories <andrew_coleman@uk.ibm.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

This document defines the XQuery and XPath Data Model 4.0, which is the data model of [XML Path Language (XPath) 4.0], [XSL Transformations (XSLT) Version 4.0], and [XQuery 4.0: An XML Query Language], and any other specifications that reference it. This document is the result of joint work by the [XSLT Working Group] and the [XML Query Working Group].

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.

This document is governed by the 1 March 2017 W3C Process Document.

This is a Recommendation of the W3C. It was jointly developed by the W3C XML Query Working Group and the W3C XSLT Working Group, each of which is part of the XML Activity.

This Editor's Draft specifies the XQuery and XPath Data Model (XDM) version 4.0, a fully compatible extension of XDM version 3.1.

This specification is designed to be referenced normatively from other specifications defining a host language for it; it is not intended to be implemented outside a host language. The implementability of this specification has been tested in the context of its normative inclusion in host languages defined by the XQuery 3.1 and XSLT 3.0 specifications; see the XQuery 3.1 implementation report (and, in the future, the WGs expect that there will also be an XSLT 3.0 implementation report) for details.

No substantive changes have been made to this specification since its publication as a Proposed Recommendation.

Please report errors in this document using W3C's public Bugzilla system (instructions can be found at https://www.w3.org/XML/2005/04/qt-bugzilla). If access to that system is not feasible, you may send your comments to the W3C XSLT/XPath/XQuery public comments mailing list, public-qt-comments@w3.org. It will be very helpful if you include the string “[XDM31]” in the subject line of your report, whether made in Bugzilla or in email. Please use multiple Bugzilla entries (or, if necessary, multiple email messages) if you have more than one comment to make. Archives of the comments and responses are available at https://lists.w3.org/Archives/Public/public-qt-comments/.

This document has been reviewed by W3C Members, by software developers, and by other W3C groups and interested parties, and is endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web.

This document was produced by groups operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures (W3C XML Query Working Group) and a public list of any patent disclosures (W3C XSLT Working Group) made in connection with the deliverables of each group; these pages also include instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Dedication

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


7 Function Items, Maps, and Arrays

7.1 Function Items

Changes in 4.0  

  1. Introduced the concept of function identity.   [Issue 520 PR 525 30 May 2023]

  2. The parameter names property of a function item is dropped; the property never had any effect on the semantics of the language.   [Issue 1896 ]

[Definition: A function item is an item that can be called. ] Function items have no serialization.

Note:

XDM 4.0 uses the term function item where XDM 3.1 used function. There is no distinction in meaning, but function item is preferred for clarity, because the unqualified term function has additional meanings in relation to function definitions in XSLT and XQuery.

A function item has the following properties:

  • name(xs:QName): An expanded QName, possibly absent.

  • identity: An abstract property that can be used to test whether two variables refer to the same function or to different functions. This property is exposed only for this purpose.

    Note:

    Currently, the concept of function identity is used for two purposes: firstly, when functions appear in the arguments supplied to the fn:deep-equal function; and secondly, in establishing whether the arguments and results of a function are "the same" when deciding whether the function is deterministic.

  • parameter names(xs:QName*): A list of distinct names, one for each of the function’s parameters.

    Note:

    This property is currently unused. There is no way of discovering the parameter names of a function item, and there is no functionality that depends on the parameter names.

  • signature [Definition: A function signature represents the type of a function.] The signature of a function item comprises:

    • The required types of its parameters (each one being a SequenceTypeXP)

    • The required types of the function result (also a SequenceTypeXP)

  • annotations A sequence of zero or more function annotations. [Definition: A function annotation consists of an annotation name (an instance of xs:QName) and an annotation value (an arbitrary sequence of atomic items).] Annotations are ordered and it is permitted for two annotations to share the same name.

  • body The body of a function provides the logic to map the arguments supplied in a function call into an instance of the function’s result type.

    The function body is generally one of the following:

    • a user-written construct in XPath, XQuery, XSLT, or some other host language known to the processor.

    • vendor-supplied logic internal to the processor.

    • external logic written in some third-party programming language, to be invoked by the processor using implementation-dependent mechanisms.

    These categories are not mutually exclusive; they may be used in combination.

    Note:

    The term “function body” replaces “function implementation”, to avoid confusion with the use of the term “implementation” in phrases such as “implementation-defined”.

  • captured context This includes a static and dynamic context for evaluation of the function body, as described in Section 2.2 Expression ContextXP. In particular it includes a set of nonlocal variable bindings (a mapping from xs:QName to item()*), which provides a value for each of the function’s free variables (i.e., variables referenced by the function’s body, other than locals and parameters).

    Note:

    Where the function body is implemented in XPath, XQuery, or XSLT, the captured context includes the static context for the user-written code (for example, its in-scope namespaces) as well as any nonlocal variable bindings.

    Functions implemented internally by the processor may capture specific parts of the static or dynamic context, for example fn:position#0 captures the value of the context position.

[Definition: The arity of a function item is the number of its parameters. ] The number of names in a function’s parameter names, and the number of parameter types in itsparameter types in a function's signature, must equal the function’s arity.

All function items match the generic function type function(*), which is itself a subtype of item(). A function signature defines a more specific function type, which is always a subtype of function(*). A function signature function(T1, T2, T3, ...) as TR is a subtype of another function signature function(U1, U2, U3, ...) as UR if (a) the two signatures have the same arity, (b) the return type TR is a subtype of UR, and (c) for each pair of parameter types, Tn is a supertype of Un. The rules are explained more fully in Section 3.3 Subtype RelationshipsXP. For example:

  • function(item()) as item() is a subtype of function(*)

  • function(item()) as xs:integer is a subtype of function(item()) as item()

  • function(item()) as item() is a subtype of function(xs:string) as item()

7.2 Map Items

Changes in 4.0  

  1. Constructors are added, and the single accessor function is now an iterator over the key/value pairs in the map.  [Issue 1335  20 July 2024]

  2. Ordered maps are introduced.  [Issue 1651 PR 1703 14 January 2025]

[Definition: A map item (also called simply a map) is a function item that represents an ordered sequence of key/value pairs, in which the keys are unique.] In other languages this is sometimes called a hash, dictionary, or associative array. The keys are atomic items, and each key in the map is unique (there is no other key to which it is equal). Each key is associated with a value that may be any sequence of zero or more items. There is no uniqueness constraint on values, only on keys. The semantics of equality when comparing keys are described in Section 14.2.1 fn:atomic-equalFO.

[Definition: The key/value pairs in a map are referred to as entries.]

Considered as a function item, a map is a function from atomic items to values: if M is a map and K is an atomic item, then the function call M(K) returns the value associated with the key K, if present, or an empty sequence otherwise. More specifically, the properties of a map when considered as a function item are:

  • name: absent.

  • identity: implementation dependent.

  • parameter names: A single parameter named key, in no namespace.

  • signature: function(xs:anyAtomicType) as item()*.

  • annotations: none.

  • body: equivalent to a call on map:get.

  • captured context: empty.

[Definition: A map containing exactly one entry is referred to as a single-entry map.]

[Definition: A map containing no entries is referred to as an empty map.]

Note:

Maps have no intrinsic identity separate from their content. A map can be given a transient identity, represented by an id property in its label, by applying the fn:pin function. This property is expected to be used in defining operations for deep update of maps.

[Definition: The order of entries in a map is referred to as entry order.] The entry order affects the result of functions such as map:keys and map:for-each, and also determines the order of entries when a map is serialized using the JSON output method.

Constructor and accessor functions for maps are defined in the following sections.

7.3 Array Items

Changes in 4.0 

  1. Constructors are added, and the single accessor function is now an iterator over the members of the array.  [Issue 1335  20 July 2024]

[Definition: An array item (also called simply an array) is a function item that represents an array.] [Definition: An array is an ordered list of values; these values are called the members of the array.] Unlike sequences, a member of an array can be any value (including a sequence or an array). The number of members in an array is called its size, and they are referenced by their position, in the range 1 to the size of the array.

Considered as a function item, an array is a function from integers to values: if A is an array and N is an integer, then the function call A(N) returns the Nth member of the array (counting from one). More specifically, the properties of an array, considered as a function item, are:

Considered as a function item, a map is a function from atomic items to values: if M is a map and K is an atomic item, then the function call M(K) returns the value associated with the key K, if present, or an empty sequence otherwise. More specifically, the properties of a map when considered as a function item are:

  • name: absent.

  • identity: implementation dependent.

  • parameter names: A single parameter named index, in no namespace.

  • signature: function(xs:integer) as item()*.

  • annotations: none.

  • body: equivalent to a call on array:get.

  • captured context: empty.

[Definition: An array containing exactly one member is referred to as a single-member array.]

[Definition: An array containing no members is referred to as an empty array.]

Note:

Arrays have no intrinsic identity separate from their content. An array can be given a transient identity, represented by an id property in its label, by applying the fn:pin function. This property is expected to be used in defining operations for deep update of arrays.

Constructor and accessor functions for arrays are defined in the following sections.

F Change Log (Non-Normative)

The following substantive changes have been made to this document since the XPath and XQuery Data Model 3.1 Recommendation of 21 March 2017.

  1. Use the arrows to browse significant changes since the 3.1 version of this specification.

    See 1 Introduction

  2. Sections with significant changes are marked Δ in the table of contents.

    See 1 Introduction

  3. Constructors are added, and the single accessor function is now an iterator over the key/value pairs in the map.

    See 7.2 Map Items

    Constructors are added, and the single accessor function is now an iterator over the members of the array.

    See 7.3 Array Items

  4. The parameter names property of a function item is dropped; the property never had any effect on the semantics of the language.

    See 7.1 Function Items

  5. PR 232 

    Clarified the terminology concerning atomic types and type annotations.

    See 3.1 Basic Concepts

  6. PR 525 

    Introduced the concept of function identity.

    See 7.1 Function Items

  7. PR 546 

    Relaxed the rules regarding use of non-XML characters in instances of xs:string.

    See 4.1.5 XML and XSD Versions

  8. PR 988 

    Introduced the concept of labeled items.

    See 3.3 Labeled Items

  9. PR 1361 

    The term atomic value has been replaced by atomic item.

    See 3.1 Basic Concepts

    See 5 Atomic Items

  10. PR 1703 

    Ordered maps are introduced.

    See 7.2 Map Items