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 18 February12 March 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/>

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) 4.0]. It also defines functions and operators on nodes and node sequences as defined in the [XQuery and XPath Data Model (XDM) 4.0]. 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.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document.

This document is a working draft developed and maintained by a W3C Community Group, the XQuery and XSLT Extensions Community Group unofficially known as QT4CG (where "QT" denotes Query and Transformation). This draft is work in progress and should not be considered either stable or complete. Standard W3C copyright and patent conditions apply.

The community group welcomes comments on the specification. Comments are best submitted as issues on the group's GitHub repository.

As the Community Group moves towards publishing dated, stable drafts, some features that the group thinks may likely be removed or substantially changed are marked “at risk” in their changes section. In this draft:

The community group maintains two extensive test suites, one oriented to XQuery and XPath, the other to XSLT. These can be found at qt4tests and xslt40-test respectively. New tests, or suggestions for correcting existing tests, are welcome. The test suites include extensive metadata describing the conditions for applicability of each test case as well as the expected results. They do not include any test drivers for executing the tests: each implementation is expected to provide its own test driver.

Dedication

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


12 Processing nodes

12.2 Other properties of nodes

This section specifies further functions that return properties of nodes. Nodes are formally defined in 6 Nodes DM31.

FunctionMeaning
fn:has-childrenReturns true if the supplied GNode has one or more child nodes (of any kind).
fn:in-scope-namespacesReturns the in-scope namespaces of an element node, as a map.
fn:in-scope-prefixesReturns the prefixes of the in-scope namespaces for an element node.
fn:langThis function tests whether the language of $node, or the context value if the second argument is omitted, as specified by xml:lang attributes is the same as, or is a sublanguage of, the language specified by $language.
fn:local-nameReturns the local part of the name of $node as an xs:string that is either the zero-length string, or has the lexical form of an xs:NCName.
fn:nameReturns the name of a node, as an xs:string that is either the zero-length string, or has the lexical form of an xs:QName.
fn:namespace-uriReturns the namespace URI part of the name of $node, as an xs:anyURI value.
fn:namespace-uri-for-prefixReturns the namespace URI of one of the in-scope namespaces for $element, identified by its namespace prefix.
fn:pathReturns a path expression that can be used to select the supplied node relative to the root of its containing document.
fn:rootReturns the root of the tree to which $node belongs. The function can be applied both to XNodesDM and to JNodesDM.
fn:siblingsReturns the supplied GNode together with its siblings, in document order.

12.2.1 fn:has-children

Changes in 4.0 (next | previous)

  1. Generalized to work with JNodes as well as XNodes.  [Issue 2100 PR 2149 12 August 2025]

Summary

Returns true if the supplied GNode has one or more child nodes (of any kind).

Signature
fn:has-children(
$nodeas gnode()?:= .
) as xs:boolean
Properties

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

Rules

If the argument is omitted, it defaults to the context value (.).

Provided that the supplied argument $node matches the expected type gnode()?, the result of the function call fn:has-children($node) is defined to be the same as the result of the expression fn:exists($node/child::gnode()).

Error Conditions

The following errors may be raised when $node is omitted:

  • If the context value is absentDM, type error [err:XPDY0002]XP

  • If the context value is not an instance of the sequence type gnode()?, type error [err:XPTY0004]XP.

Notes

If $node is the empty sequence the result is false.

The motivation for this function is to support streamed evaluation. According to the streaming rules in [XSL Transformations (XSLT) Version 4.0], the following construct is not streamable:

<xsl:if test="exists(row)">
  <ulist>
    <xsl:for-each select="row">
      <item><xsl:value-of select="."/></item>
    </xsl:for-each>
  </ulist>
</xsl:if>

This is because it makes two downward selections to read the child row elements. The use of fn:has-children in the xsl:if conditional is intended to circumvent this restriction.

Although the function was introduced to support streaming use cases, it has general utility as a convenience function.

If the supplied argument is a map or an array, it will automatically be coerced to a JNode.

Examples
Variables
let $e := <doc>
  <p id="alpha">One</p>
  <p/>
  <p>Three</p>
  <?pi 3.14159?>
</doc>
ExpressionResult
has-children($e)

true()

has-children($e//p[1])

true()

has-children($e//p[2])

false()

has-children($e//p[3])

true()

has-children($e//processing-instruction())

false()

has-children($e//p[1]/text())

false()

has-children($e//p[1]/@id)

false()

jtree([1,2,3]) => has-children()
[1,2,3] => has-children()

true()

jtree([]) => has-children()
[] => has-children()

false()

12.2.9 fn:path

Changes in 4.0 (next | previous)

  1. Options are added to customize the form of the output.  [Issues 332 1660 PRs 1620 1886 29 November 2024]

  2. The function is extended to handle JNodes.  [Issue 2100 PR 2149 5 August 2025]

Summary

Returns a path expression that can be used to select the supplied node relative to the root of its containing document.

Signature
fn:path(
$nodeas gnode()?:= .,
$optionsas map(*)?:= {}
) as xs:string?
Properties

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

Rules

The behavior of the function if the $nodeargument is omitted is exactly the same as if the context value (.) had been passed as the argument.

If $node is the empty sequence, the function returns the empty sequence.

The $options argument, if present, defines additional parameters controlling how the output is formatted. The option parameter conventions apply. The options available are as follows:

record(
origin?as gnode()?,
lexical?as xs:boolean,
namespaces?as map((xs:NCName | enum('')), xs:anyURI)?,
indexes?as xs:boolean
)
KeyMeaning

origin?

A GNode, which must be an ancestor of $node. If present, the returned path will be a relative path that selects $node starting from the supplied origin node, rather than from the root of the containing tree.
  • Type: gnode()?

  • Default: ()

lexical?

If true, the names of element nodes in the path are represented by the result of a call on the name function applied to each element. The result in this case does not contain sufficient information to identify the namespace URI of the element.
  • Type: xs:boolean

  • Default: false

namespaces?

A map from namespace prefixes to namespace URIs, such as might be returned by the function fn:in-scope-namespaces. If a prefix is available for a given URI, it is used in preference to using Q{uri}local notation.
  • Type: map((xs:NCName | enum('')), xs:anyURI)?

  • Default: ()

indexes?

If true, the returned path includes the index positions of nodes. If false, only the node names are included.
  • Type: xs:boolean

  • Default: true

Let R be the GNode supplied in the origin option, or the root GNode of the tree containing $node otherwise.

If $node is a document node, or a JNode with no parent, the function returns the string "/".

Otherwise, the function returns a string that consists of a sequence of steps, one for each ancestor-or-self of $node that is not an ancestor-or-self of R.

If R is an XNode other than a document node and the origin option is absent or empty, then this string is preceded by a string notionally representing a call to the fn:root function, expressed as follows:

  • If the lexical option is present with the value true, then the string "fn:root()".

  • If the namespaces option is present and defines a mapping from a non empty prefix P to the namespace URI http://www.w3.org/2005/xpath-functions, then "P:root()"

  • If the namespaces option is present and defines a mapping from the empty string to the namespace URI http://www.w3.org/2005/xpath-functions, then "root()"

  • Otherwise, "Q{http://www.w3.org/2005/xpath-functions}root()".

Each step is the concatenation of:

  1. The character "/", which is omitted for the first step if the origin option is present;

  2. A string whose form depends on the kind of node selected by that step, as follows:

    1. For an element node, the concatenation of:

      1. A representation of the element name, chosen as follows:

        1. If the lexical option is present with the value true, then the result of applying the name function to the element node.

        2. Otherwise, if the namespaces option is present and the element is in a namespace U and the namespaces option includes a mapping from a prefix P to the namespace U, then the string P:L, where L is the local part of the element name. If there is more than one such prefix, then one of them is chosen arbitrarily.

        3. Otherwise, if the namespaces option is present and the element is in a namespace U and the namespaces option includes a mapping from the zero-length string to the namespace U, then the local part of the element name.

        4. Otherwise, if the namespaces option is present and the element is in no namespace and the namespaces option includes no mapping from the zero-length string to any namespace, then the local part of the element name.

        5. Otherwise, the string Q{U}L, where U is the namespace URI of the element name or the empty string if the element is in no namespace, and L is the local part of the element name.

      2. Unless the indexes option is present with the value false, a string in the form [position] where position is an integer representing the one-based position of the selected node among its like-named siblings.

    2. For an attribute node, the concatenation of:

      1. The character "@"

      2. If the lexical option is present with the value true, then the result of applying the name function to the attribute node.

      3. Otherwise, if the attribute node is in no namespace, the local part of the attribute name.

      4. Otherwise, if the namespaces option is present, and if it includes a mapping from a non-empty namespace prefix P to the namespace URI of the attribute, then a string in the form P:L, where L is the local part of the attribute name. If there is more than one such prefix, then one of them is chosen arbitrarily.

      5. Otherwise, the string Q{U}L, where U is the namespace URI of the attribute name, and L is the local part of the attribute name.

    3. For a text node: text()[position] where position is an integer representing the position of the selected node among its text node siblings.

      The suffix [position] is omitted if the indexes option is present with the value false.

    4. For a comment node: comment()[position] where position is an integer representing the position of the selected node among its comment node siblings.

      The suffix [position] is omitted if the indexes option is present with the value false.

    5. For a processing-instruction node: processing-instruction(local)[position] where local is the name of the processing instruction node and position is an integer representing the position of the selected node among its like-named processing-instruction node siblings.

      The suffix [position] is omitted if the indexes option is present with the value false.

    6. For a namespace node:

      1. If the namespace node has a name: namespace::prefix, where prefix is the local part of the name of the namespace node (which represents the namespace prefix).

      2. If the namespace node has no name (that is, if it represents the default namespace): namespace::*[Ulocal-name() = ""]

        Here Ulocal-name() represents a call on the function fn:local-name and is formatted using the same conventions as the call on fn:root described earlier.

    7. For a JNode where the ·content· property of the parent is an array, then as the string *[N] where N is the value of the ·selector· property.

    8. For any other JNode (including the case where the ·content· property of the parent is a map):

      1. If the value is an xs:string, xs:untypedAtomic, or xs:anyURI that is castable to xs:NCName, then the result of casting the value to xs:NCName.

      2. If the value is an xs:string, xs:untypedAtomic, or xs:anyURI that is not castable to xs:NCName, then then as the string get("S") where S is the string value.

      3. If the value is numeric, then as the string get(N) where N is the result of casting the numeric value to xs:string.

      4. If the value is an xs:QName, then as the string get(#Q{uri}local) where uri and local are the namespace URI and local name parts of the QName.

      5. If the value is an xs:boolean, then as the string get(true()) or get(false()).

      6. If the value is of any other type, then as the string get(xs:T("S")) where T is the local part of the most specific built-in atomic type of which the value is an instance, and S is the result of casting the value to xs:string.

      TODO: Better handling of the case where the parent is neither a map nor an array, for example where it is a sequence of several maps or several arrays. It's hard to provide a better path for these when there is no AxisStep for selecting within such values.

Error Conditions

The following errors may be raised when $node is omitted:

  • If the context value is absentDM, type error [err:XPDY0002]XP

  • If the context value is not an instance of the sequence type gnodenode()?, type error [err:XPTY0004]XP.

If the value of the origin option is a node that is not an ancestor of $node (or in the absence of $node, the context value), dynamic error [err:FOPA0001].

Notes

Using the namespaces option to shorten the generated path is often convenient, but the resulting path may be unusable if the input tree contains multiple bindings for the same prefix.

Similarly, using the lexical option is convenient if there is no need for precise namespace information: it is especially suitable when the containing node tree declares no namespaces.

If the supplied argument is a map or an array, it will automatically be coerced to a JNode. This however is not useful, because this will be a root JNode, yielding the path /.

Examples
Variables
let $e := document {            
  <p xmlns="http://example.com/one" xml:lang="de" author="Friedrich von Schiller">
Freude, schöner Götterfunken,<br/>
Tochter aus Elysium,<br/>
Wir betreten feuertrunken,<br/>
Himmlische, dein Heiligtum.
</p>}
let $emp := 
  <employee xml:id="ID21256">
     <empnr>E21256</empnr>
     <first>John</first>
     <last>Brown</last>
  </employee>
Expression:
path($e)
Result:
'/'
Expression:
path($e/*:p)
Result:
'/Q{http://example.com/one}p[1]'
Expression:
path($e/*:p, { 'namespaces': in-scope-namespaces($e/*) })
Result:
'/p[1]'
Expression:
path($e/*:p, { 'indexes': false() })
Result:
'/Q{http://example.com/one}p'
Expression:
path($e/*:p/@xml:lang)
Result:
'/Q{http://example.com/one}p[1]/@Q{http://www.w3.org/XML/1998/namespace}lang'
Expression:
path($e//@xml:lang, { 'namespaces': in-scope-namespaces($e/*) })
Result:
'/p[1]/@xml:lang'
Expression:
path($e/*:p/@author)
Result:
'/Q{http://example.com/one}p[1]/@author'
Expression:
path($e/*:p/*:br[2])
Result:
'/Q{http://example.com/one}p[1]/Q{http://example.com/one}br[2]'
Expression:
path($e/*:p/*:br[2], {
  'namespaces': { 'N': 'http://example.com/one' },
  'indexes': false() 
})
Result:
'/N:p/N:br'
Expression:
path($e//text()[starts-with(normalize-space(), 'Tochter')])
Result:
'/Q{http://example.com/one}p[1]/text()[2]'
Expression:
path($e/*:p/*:br[2], { 'lexical': true() })
Result:
'/p[1]/br[2]'
Expression:
path($e/*:p/*:br[2], { 'lexical': true(), 'origin': $e/*:p })
Result:
'br[2]'
Expression:
path($emp)
Result:
'Q{http://www.w3.org/2005/xpath-functions}root()'
Expression:
path($emp/@xml:id)
Result:
'Q{http://www.w3.org/2005/xpath-functions}root()/@Q{http://www.w3.org/XML/1998/namespace}id'
Expression:
path($emp/empnr)
Result:
'Q{http://www.w3.org/2005/xpath-functions}root()/Q{}empnr[1]'
Expression:
path($emp/empnr, { 'lexical': true() })
Result:
'fn:root()/empnr[1]'
Expression:
path($emp/empnr, {
  'namespaces': {
    'fn': 'http://www.w3.org/2005/xpath-functions',
    '': ''
  }
})
Result:
'fn:root()/empnr[1]'
Expression:
let $in := [{"b":[3,4]}]
return path($in/*[1]/b/*[2])
Result:
"/*[1]/b/*[2]"
Expression:
let $in := [[{'a':1}], [{'a':2}]]
return path($in//a[. = 2])
Result:
"/*[2]/*[1]/a"

12.2.11 fn:siblings

Changes in 4.0 (next | previous)

  1. New in 4.0  [Issues 1542 1552 PRs 1547 1551 5 November 2024]

Summary

Returns the supplied GNode together with its siblings, in document order.

Signature
fn:siblings(
$nodeas gnode()?:= .
) as gnode()*
Properties

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

Rules

If the $node argument is omitted, it defaults to the context value (.).

If the value of $node is the empty sequence, the function returns the empty sequence.

If $node is a child of some parent GNode P, the function returns all the children of P (including $node), in document order, as determined by the value of $node/child::gnode().

Otherwise (specifically, if $node is parentless, or if it is an attribute or namespace node), the function returns $node.

Formal Equivalent

The effect of the function is equivalent to the result of the following XPath expression.

if ($node intersect $node/parent::gnode()/child::gnode())
then $node/parent::gnode()/child::gnode()
else $node
if ($node intersect $node/parent::node()/child::node())
then $node/parent::node()/child::node()
else $node
Error Conditions

The following errors may be raised when $node is omitted:

  • If the context value is absentDM, type error [err:XPDY0002]XP

  • If the context value is not an instance of the sequence type gnodenode()?, type error [err:XPTY0004]XP.

Notes

The result of siblings($n) (except in error cases) is the same as the result of $n/(preceding-sibling::node() | following-sibling-or-self::node()). It is also the same as $n/(preceding-sibling-or-self::node() | following-sibling::node())

As with names such as parent and child, the word sibling used here as a technical term is not a precise match to its use in describing human family relationships, but is chosen for convenience.

Examples
Variables
let $e := <doc x="X"><a>A</a>text<?pi 3.14159?></doc>
ExpressionResult
siblings($e//a) ! string()

"A", "text", "3.14159"

siblings($e//processing-instruction('pi')) ! string()

"A", "text", "3.14159"

siblings($e//@x) ! string()

"X"

[[1,2], [11,12], [13,14]]//jnode()[.='12'] => siblings() => sum()

23

12.3 Functions on sequences of nodes

This section specifies functions on sequences of nodes.

FunctionMeaning
fn:distinct-ordered-nodesRemoves duplicate GNodes and sorts the input into document order.
fn:innermostReturns every GNode within the input sequence that is not an ancestor of another member of the input sequence; the GNodes are returned in document order with duplicates eliminated.
fn:outermostReturns every GNode within the input sequence that has no ancestor that is itself a member of the input sequence; the nodes are returned in document order with duplicates eliminated.

12.3.3 fn:outermost

Changes in 4.0 (next | previous)

  1. Generalized to work with JNodes as well as XNodes.  [Issue 2100 PR 2149 12 August 2025]

Summary

Returns every GNode within the input sequence that has no ancestor that is itself a member of the input sequence; the nodes are returned in document order with duplicates eliminated.

Signature
fn:outermost(
$nodesas gnode()*
) as gnode()*
Properties

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

Rules

The effect of the function call fn:outermost($nodes) is defined to be equivalent to the result of the expression:

$nodes[not(ancestor::gnode() intersect $nodes)]/.

That is, the function takes as input a sequence of GNodes, and returns every GNode within the sequence that does not have another GNode within the sequence as an ancestor; the GNodes are returned in document order with duplicates eliminated.

Notes

The formulation $nodes except $nodes/descendant::node() might appear to be simpler, but does not correctly account for attribute nodes, as these are not descendants of their parent element.

The motivation for the function was based on XSLT streaming use cases. There are cases where the [XSL Transformations (XSLT) Version 4.0] streaming rules allow the construct outermost(//section) but do not allow //section; the function can therefore be useful in cases where it is known that sections will not be nested, as well as cases where the application actually wishes to process all sections except those that are nested within another.

If the supplied argument includes a map or an array, it will automatically be coerced to a JNode.

Examples
Expression:
parse-xml("<doc>
     <div id='a'><div id='b'><div id='c'/></div></div>
  </doc>")//div
   => outermost() => for-each(fn{string(@id)})
Result:
"a"
Expression:
[[[1], [2]], [[3], [4]], [[5], [6]]]//jnode(*, array(*))
   => outermost() =!> array:size()
[[[1], [2]], [[3], [4]], [[5], [6]]]//self::array(*)
   => outermost() =!> array:size()
Result:
3

14 Processing maps

Maps were introduced as a new datatype in XDM 3.1. This section describes functions that operate on maps.

A map is a kind of item.

[Definition] A map consists of a sequence of entries, also known as key-value pairs. Each entry comprises a key which is an arbitrary atomic item, and an arbitrary sequence called the associated value.

[Definition] Within a map, no two entries have the same key. Two atomic items K1 and K2 are the same key for this purpose if the function call fn:atomic-equal($K1, $K2) returns true.

It is not necessary that all the keys in a map should be of the same type (for example, they can include a mixture of integers and strings).

Maps are immutable, and have no identity separate from their content. For example, the map:remove function returns a map that differs from the supplied map by the omission (typically) of one entry, but the supplied map is not changed by the operation. Two calls on map:remove with the same arguments return maps that are indistinguishable from each other; there is no way of asking whether these are “the same map”.

A map can also be viewed as a function from keys to associated values. To achieve this, a map is also a function item. The function corresponding to the map has the signature function($key as xs:anyAtomicValue) as item()*. Calling the function has the same effect as calling the map:get function: the expression $map($key) returns the same result as get($map, $key). For example, if $books-by-isbn is a map whose keys are ISBNs and whose assocated values are book elements, then the expression $books-by-isbn("0470192747") returns the book element with the given ISBN. The fact that a map is a function item allows it to be passed as an argument to higher-order functions that expect a function item as one of their arguments.

14.6 Other operations on maps

This section is non-normative.

Because a map is a function item, functions that apply to functions also apply to maps. A map is an anonymous function, so fn:function-name returns the empty sequence; fn:function-arity always returns 1.

Maps may be compared using the fn:deep-equal function.

There is no function or operator to atomize a map or convert it to a string (other than fn:serialize, which can be used to serialize some maps as JSON texts).

XPath 4.0 defines a number of syntactic constructs that operate on maps. These all have equivalents in the function library:

15 Processing arrays

Arrays were introduced as a new datatype in XDM 3.1. This section describes functions that operate on arrays.

An array is an additional kind of item. An array of size N is a mapping from the integers (1 to N) to a set of values, called the members of the array, each of which is an arbitrary sequence. Because an array is an item, and therefore a sequence, arrays can be nested.

An array acts as a function from integer positions to associated values, so the function call $array($index) can be used to retrieve the array member at a given position. The function corresponding to the array has the signature function($index as xs:integer) as item()*. The fact that an array is a function item allows it to be passed as an argument to higher-order functions that expect a function item as one of their arguments.

15.3 Other Operations on Arrays

This section is non-normative.

Arrays may be compared using the fn:deep-equal function.

The XPath language provides explicit syntax for certain operations on arrays. These constructs can all be specified in terms of function primitives:

22 Constructor functions

Changes in 4.0 (next | previous)

  1. Constructor functions now have a zero-arity form; the first argument defaults to the context item.   [Issue 658 PR 662 29 August 2023]

Constructor functions are used to convert a supplied value to a given type, and the name of the function is the same as the name of the target type. This section describes constructor functions corresponding to the following types:

Constructor functions are defined for all user-defined named simple types, and for most built-in atomic, list, and union types. The only named simple types that have no constructor function are those that have no instances other than instances of their derived types: specifically, xs:anySimpleType, xs:anyAtomicType, and xs:NOTATION.

22.1 Constructor functions for XML Schema built-in atomic types

Every built-in atomic type that is defined in [XML Schema Part 2: Datatypes Second Edition], except xs:anyAtomicType and xs:NOTATION, has an associated constructor function. The type xs:untypedAtomic, defined in 2.7 Schema Information DM31 and the two derived types xs:yearMonthDuration and xs:dayTimeDuration defined in 2.7 Schema Information DM31 also have associated constructor functions. Implementations may additionally provide a constructor functions for the new datatype xs:dateTimeStamp introduced in [XSD 1.1 Part 2].

A constructor function is not defined for xs:anyAtomicType as there are no atomic items with type annotation xs:anyAtomicType at runtime, although this can be a statically inferred type. A constructor function is not defined for xs:NOTATION since it is defined as an abstract type in [XML Schema Part 2: Datatypes Second Edition]. If the static context (See 2.1.1 Static Context XP31) contains a type derived from xs:NOTATION then a constructor function is defined for it. See 22.5 Constructor functions for user-defined atomic and union types.

The form of the constructor function for an atomic type eg:TYPE is:

eg:TYPE(
$valueas xs:anyAtomicType?:= .
) as eg:TYPE?

If $arg is the empty sequence, the empty sequence is returned. For example, the signature of the constructor function corresponding to the xs:unsignedInt type defined in [XML Schema Part 2: Datatypes Second Edition] is:

xs:unsignedInt(
$argas xs:anyAtomicType?:= .
) as xs:unsignedInt?

Calling the constructor function xs:unsignedInt(12) returns the xs:unsignedInt value 12. Another call of that constructor function that returns the same xs:unsignedInt value is xs:unsignedInt("12").

The same result would also be returned if the constructor function were to be called with a node that had a typed value equal to the xs:unsignedInt 12. Because the declared parameter type for the argument is xs:anyAtomicType?, the coercion rules will atomize the supplied argument (see 2.4.2 Atomization XP31) to extract its typed value and then call the constructor with the atomized value.

Calling the constructor function xs:unsignedInt(12) returns the xs:unsignedInt value 12. Another call of that constructor function that returns the same xs:unsignedInt value is xs:unsignedInt("12"). The same result would also be returned if the constructor function were to be called with a node that had a typed value equal to the xs:unsignedInt 12. The standard features described in 2.4.2 Atomization XP31 would atomize the node to extract its typed value and then call the constructor with that value. If the value passed to a constructor function, after atomization, is not in the lexical space of the datatype to be constructed, and cannot be converted to a value in the value space of the datatype under the rules in 23 Castingthis specification, then an dynamic error is raised [err:FORG0001].

The semantics of the constructor function xs:TYPE(arg) are identical to the semantics of arg cast as xs:TYPE? . See 23 Casting.

If the argument to a constructor function is a literal, the result of the function may be evaluated statically; if an error is found during such evaluation, it may be reported as a static error.

Special rules apply to constructor functions for xs:QName and types derived from xs:QName and xs:NOTATION. See 22.2 Constructor functions for xs:QName and xs:NOTATION.

The argument is optional, and defaults to the context value (which will be atomized if necessary).

The following constructor functions for the built-in atomic types are supported:

  • xs:string(
    $valueas xs:anyAtomicType?:= .
    ) as xs:string?
  • xs:boolean(
    $valueas xs:anyAtomicType?:= .
    ) as xs:boolean?
  • xs:decimal(
    $valueas xs:anyAtomicType?:= .
    ) as xs:decimal?
  • xs:float(
    $valueas xs:anyAtomicType?:= .
    ) as xs:float?

    Implementations should return negative zero for xs:float("-0.0E0"). But because [XML Schema Part 2: Datatypes Second Edition] does not distinguish between the values positive zero and negative zero, implementations may return positive zero in this case.

  • xs:double(
    $valueas xs:anyAtomicType?:= .
    ) as xs:double?

    Implementations should return negative zero for xs:double("-0.0E0"). But because [XML Schema Part 2: Datatypes Second Edition] does not distinguish between the values positive zero and negative zero, implementations may return positive zero in this case.

  • xs:duration(
    $valueas xs:anyAtomicType?:= .
    ) as xs:duration?
  • xs:dateTime(
    $valueas xs:anyAtomicType?:= .
    ) as xs:dateTime?
  • xs:time(
    $valueas xs:anyAtomicType?:= .
    ) as xs:time?
  • xs:date(
    $valueas xs:anyAtomicType?:= .
    ) as xs:date?
  • xs:gYearMonth(
    $valueas xs:anyAtomicType?:= .
    ) as xs:gYearMonth?
  • xs:gYear(
    $valueas xs:anyAtomicType?:= .
    ) as xs:gYear?
  • xs:gMonthDay(
    $valueas xs:anyAtomicType?:= .
    ) as xs:gMonthDay?
  • xs:gDay(
    $valueas xs:anyAtomicType?:= .
    ) as xs:gDay?
  • xs:gMonth(
    $valueas xs:anyAtomicType?:= .
    ) as xs:gMonth?
  • xs:hexBinary(
    $valueas xs:anyAtomicType?:= .
    ) as xs:hexBinary?
  • xs:base64Binary(
    $valueas xs:anyAtomicType?:= .
    ) as xs:base64Binary?
  • xs:anyURI(
    $valueas xs:anyAtomicType?:= .
    ) as xs:anyURI?
  • xs:QName(
    $valueas xs:anyAtomicType?:= .
    ) as xs:QName?

    See 22.2 Constructor functions for xs:QName and xs:NOTATION for special rules.

  • xs:normalizedString(
    $valueas xs:anyAtomicType?:= .
    ) as xs:normalizedString?
  • xs:token(
    $valueas xs:anyAtomicType?:= .
    ) as xs:token?
  • xs:language(
    $valueas xs:anyAtomicType?:= .
    ) as xs:language?
  • xs:NMTOKEN(
    $valueas xs:anyAtomicType?:= .
    ) as xs:NMTOKEN?
  • xs:Name(
    $valueas xs:anyAtomicType?:= .
    ) as xs:Name?
  • xs:NCName(
    $valueas xs:anyAtomicType?:= .
    ) as xs:NCName?
  • xs:ID(
    $valueas xs:anyAtomicType?:= .
    ) as xs:ID?
  • xs:IDREF(
    $valueas xs:anyAtomicType?:= .
    ) as xs:IDREF?
  • xs:ENTITY(
    $valueas xs:anyAtomicType?:= .
    ) as xs:ENTITY?

    See 23.1.10 Casting to xs:ENTITY for rules related to constructing values of type xs:ENTITY and types derived from it.

  • xs:integer(
    $valueas xs:anyAtomicType?:= .
    ) as xs:integer?
  • xs:nonPositiveInteger(
    $valueas xs:anyAtomicType?:= .
    ) as xs:nonPositiveInteger?
  • xs:negativeInteger(
    $valueas xs:anyAtomicType?:= .
    ) as xs:negativeInteger?
  • xs:long(
    $valueas xs:anyAtomicType?:= .
    ) as xs:long?
  • xs:int(
    $valueas xs:anyAtomicType?:= .
    ) as xs:int?
  • xs:short(
    $valueas xs:anyAtomicType?:= .
    ) as xs:short?
  • xs:byte(
    $valueas xs:anyAtomicType?:= .
    ) as xs:byte?
  • xs:nonNegativeInteger(
    $valueas xs:anyAtomicType?:= .
    ) as xs:nonNegativeInteger?
  • xs:unsignedLong(
    $valueas xs:anyAtomicType?:= .
    ) as xs:unsignedLong?
  • xs:unsignedInt(
    $valueas xs:anyAtomicType?:= .
    ) as xs:unsignedInt?
  • xs:unsignedShort(
    $valueas xs:anyAtomicType?:= .
    ) as xs:unsignedShort?
  • xs:unsignedByte(
    $valueas xs:anyAtomicType?:= .
    ) as xs:unsignedByte?
  • xs:positiveInteger(
    $valueas xs:anyAtomicType?:= .
    ) as xs:positiveInteger?
  • xs:yearMonthDuration(
    $valueas xs:anyAtomicType?:= .
    ) as xs:yearMonthDuration?
  • xs:dayTimeDuration(
    $valueas xs:anyAtomicType?:= .
    ) as xs:dayTimeDuration?
  • xs:untypedAtomic(
    $valueas xs:anyAtomicType?:= .
    ) as xs:untypedAtomic?
  • xs:dateTimeStamp(
    $valueas xs:anyAtomicType?:= .
    ) as xs:dateTimeStamp?

    Available only if the implementation supports XSD 1.1.