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

XPath and XQuery Functions and Operators 4.0

W3C Editor's Draft 23 February 2026

This version:
https://qt4cg.org/specifications/xpath-functions-40/
Latest version of XPath and XQuery Functions and Operators 4.0:
https://qt4cg.org/specifications/xpath-functions-40/
Most recent Recommendation of XPath and XQuery Functions and Operators:
https://www.w3.org/TR/2017/REC-xpath-functions-31-20170321/
Editor:
Michael Kay, Saxonica <http://www.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: Specification in XML format and XML function catalog.


Abstract

This document defines constructor functions, operators, and functions on the datatypes defined in [XML Schema Part 2: Datatypes Second Edition] and the datatypes defined in [XQuery and XPath Data Model (XDM) 3.1]. It also defines functions and operators on nodes and node sequences as defined in the [XQuery and XPath Data Model (XDM) 3.1]. These functions and operators are defined for use in [XML Path Language (XPath) 4.0] and [XQuery 4.0: An XML Query Language] and [XSL Transformations (XSLT) Version 4.0] and other related XML standards. The signatures and summaries of functions defined in this document are available at: http://www.w3.org/2005/xpath-functions/.

A summary of changes since version 3.1 is provided at G Changes since 3.1.

Status of this Document

This version of the specification is work in progress. It is produced by the QT4 Working Group, officially the W3C XSLT 4.0 Extensions Community Group. Individual functions specified in the document may be at different stages of review, reflected in their History notes. Comments are invited, in the form of GitHub issues at https://github.com/qt4cg/qtspecs.

Dedication

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


19 Processing types

Changes in 4.0  

  1. New functions are provided to obtain information about built-in types and types defined in an imported schema.   [Issue 148 ]

The functions in this section deliver information about schema types (including simple types and complex types). These may represent built-in types (such as xs:dateTime), user-defined types found in the static context (typically because they appear in an imported schema), or types used as type annotations on schema-validated nodes.

For more information on schema types, see 1.8.2 Schema Type Hierarchy. The properties of a schema type are described in terms of the properties of a Simple Type Definition or Complex Type Definition component as described in Section 3.16.1 The Simple Type Definition Schema Component XS11-1 and Section 3.4.1 The Complex Type Definition Schema Component XS11-1 respectively. Not all properties are exposed.

The structured representation of a schema type is described in 19.1.1 Record fn:schema-type-record.

Note:

Simple properties of a schema type that can be expressed as strings or booleans are represented in this record structure directly as atomic field values, while complex properties whose values are themselves types (for example, base-type and primitive-type) are represented as functions. This is done partly to make it easier for implementations to compute complex properties on demand rather than in advance, and partly to ensure that the overall structure is always acyclic. For example, the primitive type of xs:decimal is itself xs:decimal, and if this were represented as a field value without a guarding function, serialization of the map using the JSON output method would not terminate.

19.1 Functions returning type information

FunctionMeaning
fn:schema-typeReturns a record containing information about a named schema type in the static context.
fn:type-ofReturns information about the type of a value, as a string.
fn:atomic-type-annotationReturns a record containing information about the type annotation of an atomic value.
fn:node-type-annotationReturns a record containing information about the type annotation of an element or attribute node.

19.1.1 Record fn:schema-type-record

This record type represents the properties of a simple or complex type in a schema.

NameMeaning

name

The name of the type. Empty in the case of an anonymous type. Corresponds to {name}XS11-1 and {target namespace}XS11-1 in the XSD component model for simple and complex type components.

  • Type: xs:QName?

is-simple

True for a simple type, false for a complex type.

  • Type: xs:boolean

base-type

Function item returning the base type (the type from which this type is derived by restriction or extension). The function is always present, and returns an empty sequence in the case of the type xs:anyType. Corresponds to the {base type definition}XS11-1 property in the XSD component model.

  • Type: fn() as schema-type-record?

primitive-type?

For an atomic type, a function item returning the primitive type from which this type is ultimately derived. Corresponds to the {primitive type definition}XS11-1 in the XSD component model for simple types. Absent if the type is non atomic, or if it is the simple type xs:anyAtomicType. If this is a primitive type, the function item is idempotent.

  • Type: fn() as schema-type-record

variety?

For a simple type, one of "atomic", "list", or "union", corresponding to the {variety}XS11-1 of the simple type in the XSD component model. For a complex type, one of "empty", "simple", "element-only", or "mixed", corresponding to the {content type}XS11-1.{variety}XS11-1 of the complex type in the XSD component model. The value is absent in cases where the {variety}XS11-1 in the XSD component model is absent, for example for the type xs:anySimpleType.

  • Type: enum("atomic", "list", "union", "empty", "simple", "element-only", "mixed")

members?

For a simple type with variety "union", a function that returns a sequence of records representing the member types of the union, in order, corresponding to the {member type definitions}XS11-1 property in the XSD component model. For a simple type with variety "list", a function that returns a record representing the item type of the list type, corresponding to the {item type definition}XS11-1 property in the XSD component model. In all other cases, absent.

  • Type: fn() as schema-type-record*

simple-content-type?

For a complex type with variety "simple" (that is, a complex type with simple content), a function that returns a record representing the relevant simple type, corresponding to the {content type}XS11-1.{simple type definition}XS11-1 property in the XSD complex type component. In all other cases, absent.

  • Type: fn() as schema-type-record

matches?

For a generalized atomic typeXP, a function item that can be called to establish whether the supplied atomic item is an instance of this type. In all other cases, absent.

  • Type: fn(xs:anyAtomicType) as xs:boolean

constructor?

For a simple type, a function item that can be used to construct instances of this type. In the case of a named type that is present in the dynamic context, the result is the same function as returned by fn:function-lookup applied to the type name (with arity one). For details see 20.1 Constructor functions for XML Schema built-in atomic types and 20.5 Constructor functions for user-defined atomic and union types. Constructor function items are also available for anonymous types, and for types that might not be present in the dynamic context. The field is absent for complex types and for the abstract types xs:anyAtomicType, xs:anySimpleType, and xs:NOTATION. It is also absent for all namespace-sensitivenamespace-XPsensitive types, that is, types derived from xs:QName or xs:NOTATION.

  • Type: fn(xs:anyAtomicType) as xs:anyAtomicType

*

The record type is extensible (it may contain additional fields beyond those listed).