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) 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.
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.
The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).
This section specifies further functions that return properties of nodes. Nodes are formally defined in 6 Nodes DM31.
| Function | Meaning |
|---|---|
fn:has-children | Returns true if the supplied GNode has one or more child nodes (of any kind). |
fn:in-scope-namespaces | Returns the in-scope namespaces of an element node, as a map. |
fn:in-scope-prefixes | Returns the prefixes of the in-scope namespaces for an element node. |
fn:lang | This 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-name | Returns 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:name | Returns 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-uri | Returns the namespace URI part of the name of $node, as an xs:anyURI value. |
fn:namespace-uri-for-prefix | Returns the namespace URI of one of the in-scope namespaces for $element, identified by its namespace prefix. |
fn:path | Returns a path expression that can be used to select the supplied node relative to the root of its containing document. |
fn:root | Returns the root of the tree to which $node belongs. The function can be applied both to XNodesDM and to JNodesDM. |
fn:siblings | Returns the supplied GNode together with its siblings, in document order. |
Returns true if the supplied GNode has one or more child nodes (of any kind).
fn:has-children( | ||
$node | as | := . |
) as | ||
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.
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()).
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.
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.
| Variables | |
|---|---|
let $e := <doc> <p id="alpha">One</p> <p/> <p>Three</p> <?pi 3.14159?> </doc> | |
| Expression | Result |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns a path expression that can be used to select the supplied node relative to the root of its containing document.
fn:path( | ||
$node | as | := ., |
$options | as | := {} |
) as | ||
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.
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 |
) | |
| Key | Meaning |
|---|---|
| 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.
|
| 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.
|
| 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.
|
| If true, the returned path includes the index positions of nodes. If false, only the node names are included.
|
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:
The character "/", which is omitted for the first step if the origin option is present;
A string whose form depends on the kind of node selected by that step, as follows:
For an element node, the concatenation of:
A representation of the element name, chosen as follows:
If the lexical option is present with the value true, then the result of applying the name function to the element node.
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.
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.
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.
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.
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.
For an attribute node, the concatenation of:
The character "@"
If the lexical option is present with the value true, then the result of applying the name function to the attribute node.
Otherwise, if the attribute node is in no namespace, the local part of the attribute name.
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.
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.
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.
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.
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.
For a namespace node:
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).
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.
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.
For any other JNode (including the case where the ·content· property of the parent is a map):
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.
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.
If the value is numeric, then as the string get(N) where N is the result of casting the numeric value to xs:string.
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.
If the value is an xs:boolean, then as the string get(true()) or get(false()).
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.
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].
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 /.
| 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" |
Returns the supplied GNode together with its siblings, in document order.
fn:siblings( | ||
$node | as | := . |
) as | ||
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.
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.
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 $nodeif ($node intersect $node/parent::node()/child::node())
then $node/parent::node()/child::node()
else $nodeThe 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.
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.
| Variables | |
|---|---|
let $e := <doc x="X"><a>A</a>text<?pi 3.14159?></doc> | |
| Expression | Result |
|---|---|
|
|
|
|
|
|
|
|
This section specifies functions on sequences of nodes.
| Function | Meaning |
|---|---|
fn:distinct-ordered-nodes | Removes duplicate GNodes and sorts the input into document order. |
fn:innermost | Returns 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:outermost | 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. |
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.
fn:outermost( | ||
$nodes | as | |
) as | ||
This function is deterministic, context-independent, and focus-independent.
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.
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.
| 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 |
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.
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:
The expression {} creates the empty map (see [XML Path Language (XPath) 4.0] section 4.15.1.14.14.1.1 Map Constructors). This is equivalent to the effect of the data model primitive dm:empty-map(). Using user-visible functions the same can be achieved by calling map:build or map:merge, supplying the empty sequence as the argument.
The map constructor { K1 : V1, K2 : V2, ... , Kn : Vn } is equivalent to map:merge((map:entry(K1, V1), map:entry(K1, V1), ..., map:entry(Kn, Vn)), { "duplicates": "reject" })
The lookup expression $map?* (see [XML Path Language (XPath) 4.0] section 4.15.34.14.3 Lookup Expressions) is equivalent to map:items($map).
The lookup expression $map?K, where K is a key value, is equivalent to map:get($map, K)
The expression for key $k value $v in $map return EXPR (see [XQuery 4.0: An XML Query Language] section 4.13.2 For Clause and [XML Path Language (XPath) 4.0] section 4.14.14.13.1 For Expressions) is equivalent to the function call map:for-each($map, fn($k, $v) { EXPR }).
Maps can be filtered using the construct $map?[predicate] (see [XML Path Language (XPath) 4.0] section 4.15.54.14.5 Filter Expressions for Maps and 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.
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:
The empty array can be constructed using either of the expressions [] or array{}. The effect is the same as the data model primitive dm:empty-array(()) (see [XML Path Language (XPath) 4.0] section 4.15.2.14.14.2.1 Array Constructors). Using user-visible functions it can be achieved by calling array:build(()) or array:of-members(()).
The expression array { $sequence } constructs an array whose members are the items in $sequence. Every member of this array will be a singleton item. The effect is the same as array:build($sequence).
The expression [E1, E2, E3, ..., En] constructs an array in which E1 is the first member, E2 is the second member, and so on. The result is equivalent to the expression [] => array:append(E1) => array:append(E2) => ... => array:append(En))).
The lookup expression $array?* returns the sequence concatenationXP of the members of the array. It is equivalent to calling array:fold-left($array, (), fn($result, $next){ $result, $next }).
The lookup expression $array?$N, where $N is an integer within the bounds of the array, is equivalent to array:get($array, $N).
Similarly, applying the array as a function, $array($N), is also equivalent to array:get($array, [$N])
The expression for member $m in $array return EXPR is equivalent to array:for-each($array, fn($m){ EXPR }) (see [XQuery 4.0: An XML Query Language] section 4.13.2 For Clause and [XML Path Language (XPath) 4.0] section 4.14.14.13.1 For Expressions).
Arrays can be filtered using the construct $array?[predicate] (see [XML Path Language (XPath) 4.0] section 4.15.54.14.5 Filter Expressions for Maps and Arrays).
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:
Simple types (atomic types, union types, and list types as defined in [XML Schema Part 2: Datatypes Second Edition]), which are present in the static context either because they appear in the in-scope schema typesXP or because they appear as named item typesXP.
These constructor functions always take a single argument.
Record types defined as named item typesXP.
These take one argument for each named field of the record type. Constructor functions for record types are defined in 22.6 Constructor functions for named record 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.
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( | ||
$value | as | := . |
) as | ||
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( | ||
$arg | as | := . |
) as | ||
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( | ||
$value | as | := . |
) as | ||
xs:boolean( | ||
$value | as | := . |
) as | ||
xs:decimal( | ||
$value | as | := . |
) as | ||
xs:float( | ||
$value | as | := . |
) as | ||
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( | ||
$value | as | := . |
) as | ||
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( | ||
$value | as | := . |
) as | ||
xs:dateTime( | ||
$value | as | := . |
) as | ||
xs:time( | ||
$value | as | := . |
) as | ||
xs:date( | ||
$value | as | := . |
) as | ||
xs:gYearMonth( | ||
$value | as | := . |
) as | ||
xs:gYear( | ||
$value | as | := . |
) as | ||
xs:gMonthDay( | ||
$value | as | := . |
) as | ||
xs:gDay( | ||
$value | as | := . |
) as | ||
xs:gMonth( | ||
$value | as | := . |
) as | ||
xs:hexBinary( | ||
$value | as | := . |
) as | ||
xs:base64Binary( | ||
$value | as | := . |
) as | ||
xs:anyURI( | ||
$value | as | := . |
) as | ||
xs:QName( | ||
$value | as | := . |
) as | ||
See 22.2 Constructor functions for xs:QName and xs:NOTATION for special rules.
xs:normalizedString( | ||
$value | as | := . |
) as | ||
xs:token( | ||
$value | as | := . |
) as | ||
xs:language( | ||
$value | as | := . |
) as | ||
xs:NMTOKEN( | ||
$value | as | := . |
) as | ||
xs:Name( | ||
$value | as | := . |
) as | ||
xs:NCName( | ||
$value | as | := . |
) as | ||
xs:ID( | ||
$value | as | := . |
) as | ||
xs:IDREF( | ||
$value | as | := . |
) as | ||
xs:ENTITY( | ||
$value | as | := . |
) as | ||
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( | ||
$value | as | := . |
) as | ||
xs:nonPositiveInteger( | ||
$value | as | := . |
) as | ||
xs:negativeInteger( | ||
$value | as | := . |
) as | ||
xs:long( | ||
$value | as | := . |
) as | ||
xs:int( | ||
$value | as | := . |
) as | ||
xs:short( | ||
$value | as | := . |
) as | ||
xs:byte( | ||
$value | as | := . |
) as | ||
xs:nonNegativeInteger( | ||
$value | as | := . |
) as | ||
xs:unsignedLong( | ||
$value | as | := . |
) as | ||
xs:unsignedInt( | ||
$value | as | := . |
) as | ||
xs:unsignedShort( | ||
$value | as | := . |
) as | ||
xs:unsignedByte( | ||
$value | as | := . |
) as | ||
xs:positiveInteger( | ||
$value | as | := . |
) as | ||
xs:yearMonthDuration( | ||
$value | as | := . |
) as | ||
xs:dayTimeDuration( | ||
$value | as | := . |
) as | ||
xs:untypedAtomic( | ||
$value | as | := . |
) as | ||
xs:dateTimeStamp( | ||
$value | as | := . |
) as | ||
Available only if the implementation supports XSD 1.1.