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).
Accessors and their semantics are described in [XQuery and XPath Data Model (XDM) 3.1]. Some of these accessors are exposed to the user through the functions described below.
Each of these functions has an arity-zero signature which is equivalent to the arity-one form, with the context value supplied as the implicit first argument. In addition, each of the arity-one functions accepts an empty sequence as the argument, in which case it generally delivers an empty sequence as the result: the exception is fn:string, which delivers a zero-length string.
| Function | Accessor | Accepts | Returns |
|---|---|---|---|
fn:node-name | node-name | node (optional) | xs:QName (optional) |
fn:nilled | nilled | node (optional) | xs:boolean (optional) |
fn:string | string-value | item (optional) | xs:string |
fn:data | typed-value | zero or more items | a sequence of atomic items |
fn:base-uri | base-uri | node (optional) | xs:anyURI (optional) |
fn:document-uri | document-uri | node (optional) | xs:anyURI (optional) |
| Function | Meaning |
|---|---|
fn:node-name | Returns the name of a node, as an xs:QName. |
fn:nilled | Returns true for an element that is nilled. |
fn:string | Returns the value of $value represented as an xs:string. |
fn:data | Returns the result of atomizing a sequence. This process flattens arrays, and replaces nodes by their typed values. |
fn:base-uri | Returns the base URI of a node. |
fn:document-uri | Returns the URI of a resource where a document can be found, if available. |
Returns the name of a node, as an xs:QName.
fn:node-name( | ||
$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 (.).
If $node is the empty sequence, the empty sequence is returned.
Otherwise, the function returns the result of the dm:node-name accessor as defined in [XQuery and XPath Data Model (XDM) 3.1] (see Section 6.7.10 node-name AccessorDM).
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
For element and attribute nodes, the name of the node is returned as an xs:QName, retaining the prefix, namespace URI, and local part.
For processing instructions, the name of the node is returned as an xs:QName in which the prefix and namespace URI are absentDM.
For a namespace node, the function returns an empty sequence if the node represents the default namespace; otherwise it returns an xs:QName in which prefix and namespace URI are absentDM and the local part is the namespace prefix being bound.
For all other kinds of node, the function returns the empty sequence.
| Variables | |
|---|---|
let $e := <doc> <p id="alpha" xml:id="beta">One</p> <p id="gamma" xmlns="http://example.com/ns">Two</p> <ex:p id="delta" xmlns:ex="http://example.com/ns">Three</ex:p> <?pi 3.14159?> </doc> | |
| Expression | Result |
|---|---|
| QName("", "p") |
| QName("http://example.com/ns", "p") |
| QName("http://example.com/ns", "ex:p") |
| QName("", "pi") |
| () |
| QName("", "id") |
| #xml:id |
Returns true for an element that is nilled.
fn:nilled( | ||
$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 (.).
If $node is the empty sequence, the function returns the empty sequence.
Otherwise the function returns the result of the dm:nilled accessor as defined in [XQuery and XPath Data Model (XDM) 3.1] (see Section 6.7.8 nilled AccessorDM).
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
If $node is not an element node, the function returns the empty sequence.
If $node is an untyped element node, the function returns false.
In practice, the function returns true only for an element node that has the attribute xsi:nil="true" and that is successfully validated against a schema that defines the element to be nillable; the detailed rules, however, are defined in [XQuery and XPath Data Model (XDM) 3.1].
Returns the value of $value represented as an xs:string.
fn:string( | ||
$value | 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.
In the zero-argument version of the function, $value defaults to the context value. That is, calling fn:string() is equivalent to calling fn:string(.).
If $value is the empty sequence, the function returns the zero-length string.
If $value is a node, the function returns the string value of the node, as obtained using the dm:string-value accessor defined in [XQuery and XPath Data Model (XDM) 3.1] (see Section 6.7.12 string-value AccessorDM).
If $value is an atomic item, the function returns the result of the expression $value cast as xs:string (see 22 Casting).
In all other cases, a dynamic error occurs (see below).
The following errors may be raised when $value is omitted:
If the context value is absentDM, type error [err:XPDY0002]XP.
If the context value is not a singlean instance of the sequence type item()?, type error [err:XPTY0004]XP.
A type error is raised [err:FOTY0014] if $value is a function item (this includes maps and arrays).
Every node has a string value, even an element with element-only content (which has no typed value). Moreover, casting an atomic item to a string always succeeds. Functions, maps, and arrays have no string value, so these are the only arguments that satisfy the type signature but cause failure.
| Variables | |
|---|---|
let $para := <para>There lived a <term author="Tolkien">hobbit</term>.</para> | |
| Expression | Result |
|---|---|
| "23" |
| "false" |
| "Paris" |
| Raises error XPTY0004. |
| Raises error FOTY0014. |
| Raises error FOTY0014. |
| "There lived a hobbit." |
Returns the base URI of a node.
fn:base-uri( | ||
$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.
The zero-argument version of the function returns the base URI of the context node: it is equivalent to calling fn:base-uri(.).
The single-argument version of the function behaves as follows:
If $node is the empty sequence, the function returns the empty sequence.
Otherwise, the function returns the value of the dm:base-uri accessor applied to the node $node. This accessor is defined, for each kind of node, in the XDM specification (See Section 6.7.2 base-uri AccessorDM).
Note:
As explained in XDM, document, element and processing-instruction nodes have a base-uri property which may be empty. The base-uri property for all other node kinds is the empty sequence. The dm:base-uri accessor returns the base-uri property of a node if it exists and is non-empty; otherwise it returns the result of applying the dm:base-uri accessor to its parent, recursively. If the node does not have a parent, or if the recursive ascent up the ancestor chain encounters a parentless node whose base-uri property is empty, the empty sequence is returned. In the case of namespace nodes, however, the result is always an empty sequence — it does not depend on the base URI of the parent element.
See also fn:static-base-uri.
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
Returns the URI of a resource where a document can be found, if available.
fn:document-uri( | ||
$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 (.).
If $node is the empty sequence, the function returns the empty sequence.
If $node is not a document node, the function returns the empty sequence.
Otherwise, the function returns the value of the document-uri accessor applied to $node, as defined in [XQuery and XPath Data Model (XDM) 3.1] (See Section 6.6.1.2 AccessorsDM).
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
In the 3.1 version of this specification, it was mandated that two distinct documents could not have the same document-uri property: more specifically, it was guaranteed that for any document node $D, either document-uri($D) would be absent, or doc(document-uri($D)) would return $D.
For various reasons, this constraint has proved impractical. Different parts of an application may read the same external resource in different ways, for example with or without validation or whitespace stripping, leading to different document nodes derived from the same external resource having the same document-uri property. In addition, the specification explicitly allows implementations, at user request, to relax the requirements for determinism of resource access functions, which makes it possible for multiple calls of functions such as fn:doc, fn:json-doc, or fn:collection to return different results for the same supplied URI.
Although the uniqueness of the document-uri property is no longer an absolute constraint, it is still desirable that implementations should where possible respect the principle that URIs are usable as identifiers for resources.
In the case of a document node $D returned by the fn:doc function, it will generally be the case that fn:document-uri($D) returns a URI $U such that a call on fn:doc($U) in the same dynamic context will return the same document node $D. The URI $U will not necessarily be the same URI that was originally passed to the fn:doc function, since several URIs may identify the same resource.
It is recommended that implementations of fn:collection should ensure that any documents included in the returned collection, if they have a non-empty fn:document-uri property, should be such that a call on fn:doc supplying this URI returns the same document node.
This section specifies further functions on nodes. Nodes are formally defined in Section 6 Nodes DM31.
| Function | Meaning |
|---|---|
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: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:namespace-uri | Returns the namespace URI part of the name of $node, as an xs:anyURI value. |
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:root | Returns the root of the tree to which $node belongs. This will usually, but not necessarily, be a document node. |
fn:path | Returns a path expression that can be used to select the supplied node relative to the root of its containing document. |
fn:has-children | Returns true if the supplied node has one or more child nodes (of any kind). |
fn:siblings | Returns the supplied node together with its siblings, in document order. |
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:name( | ||
$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 (.).
If the argument is supplied and is the empty sequence, the function returns the zero-length string.
If the node identified by $node has no name (that is, if it is a document node, a comment, a text node, or a namespace node having no name), the function returns the zero-length string.
Otherwise, the function returns the value of the expression fn:string(fn:node-name($node)).
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
Because the result depends on the choice of namespace prefixes in the source document, it is not good practice to use the result of this function for anything other than display purposes. For example, the test name(.) = 'my:profile' will fail if the source document uses an unexpected namespace prefix. Such a test (assuming it relates to an element node) is better written as boolean(self::my:profile).
| Variables | |
|---|---|
let $e := <doc> <p id="alpha" xml:id="beta">One</p> <p id="gamma" xmlns="http://example.com/ns">Two</p> <ex:p id="delta" xmlns:ex="http://example.com/ns">Three</ex:p> <?pi 3.14159?> </doc> | |
| Expression | Result |
|---|---|
| "p" |
| "p" |
| "ex:p" |
| "pi" |
| "" |
| "id" |
| "xml:id" |
Returns the namespace URI part of the name of $node, as an xs:anyURI value.
fn:namespace-uri( | ||
$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 node (.).
If the node identified by $node is neither an element nor an attribute node, or if it is an element or attribute node whose expanded-QName (as determined by the dm:node-name accessor in the Section 6.7.10 node-name AccessorDM) is in no namespace, then the function returns the zero-length xs:anyURI value.
Otherwise, the result will be the namespace URI part of the expanded-QName of the node identified by $node, as determined by the dm:node-name accessor defined in Section 6.7.10 node-name AccessorDM), returned as an xs:anyURI value.
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
| Variables | |
|---|---|
let $e := <doc> <p id="alpha" xml:id="beta">One</p> <p id="gamma" xmlns="http://example.com/ns">Two</p> <ex:p id="delta" xmlns:ex="http://example.com/ns">Three</ex:p> <?pi 3.14159?> </doc> | |
| Expression | Result |
|---|---|
| "" |
| "http://example.com/ns" |
| "http://example.com/ns" |
| "" |
| "" |
| "" |
| "http://www.w3.org/XML/1998/namespace" |
Returns the root of the tree to which $node belongs. This will usually, but not necessarily, be a document node.
fn:root( | ||
$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 function is called without an argument, the context value (.) is used as the default argument.
The function returns the value of the expression ($arg/ancestor-or-self::node())[1].
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
These examples use some variables which could be defined in [XQuery 4.0: An XML Query Language] as: | |
let $i := <tool>wrench</tool>
let $o := <order>{ $i }<quantity>5</quantity></order>
let $odoc := document { $o }
let $newi := $o/tool | |
Or they could be defined in [XSL Transformations (XSLT) Version 4.0] as: | |
<xsl:variable name="i" as="element()">
<tool>wrench</tool>
</xsl:variable>
<xsl:variable name="o" as="element()">
<order>
<xsl:copy-of select="$i"/>
<quantity>5</quantity>
</order>
</xsl:variable>
<xsl:variable name="odoc">
<xsl:copy-of select="$o"/>
</xsl:variable>
<xsl:variable name="newi" select="$o/tool"/> | |
| |
| |
| |
| |
The final three examples could be made type-safe by wrapping their operands with |
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 node()?, |
lexical? | as xs:boolean, |
namespaces? | as map((xs:NCName | enum('')), xs:anyURI)?, |
indexes? | as xs:boolean |
) | |
| Key | Meaning |
|---|---|
| A node, 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 elements 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 node supplied in the origin option, or the root node of the tree containing $node otherwise.
If $node is a document node, 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 not 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.
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 a singlean instance of the sequence type node()?, 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.
| 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]' |
Returns true if the supplied node 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 node()?, 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::node()).
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
If $node is an 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.
| Variables | |
|---|---|
let $e := <doc> <p id="alpha">One</p> <p/> <p>Three</p> <?pi 3.14159?> </doc> | |
| Expression | Result |
|---|---|
| true() |
| true() |
| false() |
| true() |
| false() |
| false() |
| false() |
Returns the supplied node 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 an empty sequence, the function returns an empty sequence.
If $node is a child of some parent node P, the function returns all the children of P (including $node), in document order.
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::node()/child::node()) then $node/parent::node()/child::node() else $node
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 a singlean instance of the sequence type node()?, 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 |
|---|---|
| "A", "text", "3.14159" |
| "A", "text", "3.14159" |
| "X" |
A sequence is an ordered collection of zero or more items. An item is a node, an atomic item, or a function, such as a map or an array. The terms sequence and item are defined formally in [XQuery 4.0: An XML Query Language] and [XML Path Language (XPath) 4.0].
This section defines a number of functions used to find elements by ID or IDREF value, or to generate identifiers.
| Function | Meaning |
|---|---|
fn:id | Returns the sequence of element nodes that have an ID value matching the value of one or more of the IDREF values supplied in $values. |
fn:element-with-id | Returns the sequence of element nodes that have an ID value matching the value of one or more of the IDREF values supplied in $values. |
fn:idref | Returns the sequence of element or attribute nodes with an IDREF value matching the value of one or more of the ID values supplied in $values. |
fn:generate-id | This function returns a string that uniquely identifies a given node. |
This function returns a string that uniquely identifies a given node.
fn:generate-id( | ||
$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 (.).
If the argument is the empty sequence, the result is the zero-length string.
In other cases, the function returns a string that uniquely identifies a given node. More formally, it is guaranteed that within a single execution scope, fn:codepoint-equal(fn:generate-id($N), fn:generate-id($M)) returns true if and only if ($M is $N) returns true.
The returned identifier must consist of ASCII alphanumeric characters and must start with an alphabetic character. Thus, the string is syntactically an XML name.
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 a singlean instance of the sequence type node()?, type error [err:XPTY0004]XP.
An implementation is free to generate an identifier in any convenient way provided that it always generates the same identifier for the same node and that different identifiers are always generated from different nodes. An implementation is under no obligation to generate the same identifiers each time a document is transformed or queried.
There is no guarantee that a generated unique identifier will be distinct from any unique IDs specified in the source document.
There is no inverse to this function; it is not directly possible to find the node with a given generated ID. Of course, it is possible to search a given sequence of nodes using an expression such as $nodes[generate-id()=$id].
It is advisable, but not required, for implementations to generate IDs that are distinct even when compared using a case-blind collation.
The primary use case for this function is to generate hyperlinks. For example, when generating HTML, an anchor for a given section | |
| |
and a link to that section can then be produced with code such as: | |
| |
Note that anchors generated in this way will not necessarily be the same each time a document is republished. | |
Since the keys in a map must be atomic items, it is possible to use generated IDs as surrogates for nodes when constructing a map. For example, in some implementations, testing whether a node | |
| |
and then testing for membership of the node-set using: | |
|