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).


17 Higher-order functions

17.1 Processing function items

The functions included in this section operate on function items, that is, values referring to a function.

[Definition] Functions that accept functions among their arguments, or that return functions in their result, are described in this specification as higher-order functions.

Note:

Some functions such as fn:parse-json allow the option of supplying a callback function for example to define exception behavior. Where this is not essential to the use of the function, the function has not been classified as higher-order for this purpose; in applications where function items cannot be created, these particular options will not be available.

FunctionMeaning
fn:function-lookupReturns a function item having a given name and arity, if there is one.
fn:function-nameReturns the name of the function identified by a function item.
fn:function-arityReturns the arity of the function identified by a function item.
fn:function-identityReturns a string representing the identity of a function item.
fn:function-annotationsReturns the annotations of the function item.

17.1.4 fn:function-identity

Summary

Returns a string representing the identity of a function item.

Signature
fn:function-identity(
$functionas fn(*)
) as xs:string
Properties

This function is deterministic, context-independent, and focus-independent.

Rules

The fn:function-identity function returns a string that represents the identity of $function.

The returned string has the property that fn:function-identity($f1) and fn:function-identity($f2) are codepoint-equal if and only if $f1 and $f2 have the same function identity. Apart from this property, the result is implementation-dependent.

Any label attached to a function item is ignored (see Section 3.3 Labeled ItemsDM). Specifically, if L is a labeled item then fn:function-identity(L) returns the function identity of the subject of L.

In the case of maps and arrays, the result follows the following rule: If $X and $Y are both maps or arrays then fn:function-identity($X)must not be codepoint-equal to fn:function-identity($Y) unless $X and $Y are indistinguishable, that is unless every operator or function applied to $X returns the same result as for $Y. Even in this case, however, the result of the comparison fn:function-identity($X) eq fn:function-identity($Y) is implementation-dependent.

Notes

This function enables applications to test whether two expressions or variables reference the same function item. This may be useful, for example, to allow caching of function results to avoid repeated evaluation. The results of previous function invocations might be held in a map whose key is the function identity.

The function identity, by definition, is generated upon the creation of a function item. Specific expressions that create function items have their own rules for the identity of the returned functions: for example, it is guaranteed that evaluation of a function reference to a system function with no captured context (such as fn:abs#1) will always return the same function item.

It is not meaningful to store or compare the result of calling fn:function-identity across different execution scopes, because the string used to represent the function identity will generally vary from one execution scope to another.

The result of an expression such as function-identity(abs#1) eq function-identity(abs(?)) may be either true or false, because it is implementation-dependent whether abs#1 and abs(?) return the same function item.

Similarly, function-identity({1:()}) eq function-identity(map:entry(1, ())) may be either true or false.

Labels on function items are ignored because they typically represent information about how the function item was retrieved, rather than about the item itself. For example, a function item held in a map might be retrieved using a variety of lookup expressions, which may return the same function item but with different labels.

Examples
ExpressionResult
function-identity(abs#1) eq function-identity(abs#1)
true()
function-identity(abs#1) eq function-identity(round#1)
false()
function-identity({1:0}) eq function-identity({1:1})
false()
function-identity([0]) eq function-identity([1]})
false()