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.
Copyright © 2000 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
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 H Changes since 3.1.
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.
The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).
The following functions allow dynamic loading and evaluation of XQuery queries, XSLT stylesheets, and XPath binary operators.
| Function | Meaning |
|---|---|
fn:load-xquery-module | Provides access to the public functions and global variables of a dynamically loaded XQuery library module. |
fn:transform | Invokes a transformation using a dynamically loaded XSLT stylesheet. |
fn:op | Returns a function whose effect is to apply a supplied binary operator to two arguments. |
Returns a function whose effect is to apply a supplied binary operator to two arguments.
fn:op( | ||
$operator | as | |
) as | ||
This function is deterministic, context-independent, and focus-independent.
The supplied operator must be one of:
",", "and", "or", "+", "-", "*", "div", "idiv", "mod", "=", "<", "<=", ">", ">=", "!=", "eq", "lt", "le", "gt", "ge", "ne", "<<", ">>", "precedes", "follows", "is", "is-not", "||", "|", "union", "except", "intersect", "to", "otherwise".
The result of calling fn:op("⊙"), where ⊙ is one of the above operators, is the function represented by the XPath expression:
fn($x, $y) { $x ⊙ $y }
For example, op("+") returns fn($x, $y) { $x + $y }.
A type error is raised [err:XPTY0004]XP if the supplied argument is not one of the supported operators.
The function is useful in contexts where an arity-2 callback function needs to be supplied, and a standard operator meets the requirement.
For example, the XSLT xsl:map instruction has an on-duplicates attribute that expects such a function. Specifying on-duplicates="op(',')" is equivalent to specifying on-duplicates="fn($x, $y) { $x, $y }
The function is also useful in cases where the choice of operator to apply is made dynamically.
Some operators (such as and, or, and otherwise) have custom error handling semantics, with the effect that evaluating one of the operands cannot cause an error unless the other operand has a particular value (see Section 2.4.5 Guarded ExpressionsXP). Although implementations are free to make optimizations, it should be assumed that a function call such as op('and')(X, Y) will have the normal semantics of a dynamic function call, where the arguments are evaluated in any order, and a failure evaluating any argument may cause the function call as a whole to fail.
| Expression | Result |
|---|---|
| 22, 24, 26, 28, 30 |
| 20, 20, 20, 20, 20 |