Online XPath tester








What is XPath?

XPath is a query language used for selecting nodes from XML and processing them.
It may perform operations on strings, numbers and boolean values.

Semantics legend:

"+" - 1 or more elements

"*" - 0 or more elements

"?" - optional element

XPath 2.0 introduced many new features XQuery-cośtam:
- Added support for all XML simple types
- Many new functions (tripled instruction count)
- All expressions evaluate to sequence
- Introduces conditional expressions and for-loops

XPath 3.0
- Dynamic function calls (function may be called without being referenced by name (find function in collection and call)
- Inline functions
- Namespace literals - Namespace may be embedded into function name
- Support for union types - collections containing elements of different types
- Mapping operator - '!' performs evaluation for each element in sequence and concatenates results
- Introduced maps

XPath 3.1
- New operator for function chaining '=>'
- Introduced maps that store data in pair 'key:value' - 'map{ key : value, key : value }'
- Introduced arrays - they differ from sequences in that they can be nested 'array{1, 5, 7, (10 to 20)}'

XPath 1.0 & 2.0 functions

fn:position()
Returns the position of the current context node

W3C Documentation reference: Node-Set-Functions
fn:count()
Returns the number of nodes in the node-set
Arguments:
Type Description
node-set Node-set to count nodes in
Examples:
Expression Result
count(//b:book) 5
count(//person[@id>5]) 17

W3C Documentation reference: Node-Set-Functions
fn:id()
Returns the element specified by it's unique id, requires DTD

W3C Documentation reference: Node-Set-Functions
fn:local-name()
Returns the local-name for the first node in the node-set
Arguments:
Type Description
node-set Extract first node and return its local name
Examples:
Expression Result
local-name(//b:books) b:book
local-name(//b:book) b:title

W3C Documentation reference: Node-Set-Functions
fn:local-name()
Returns the local-name for the context node

W3C Documentation reference: Node-Set-Functions
fn:namespace-uri()
Returns the namespace-uri for the first node in the node-set
Arguments:
Type Description
node-set Extract first node and return the namespace URI
Examples:
Expression Result
namespace-uri(//b:book) http://www.book.com

W3C Documentation reference: Node-Set-Functions
fn:namespace-uri()
Returns the namespace-uri for the context node

W3C Documentation reference: Node-Set-Functions
fn:name()
Returns the name for the first node in the node-set
Arguments:
Type Description
node-set (Optional) Extract first node and return QName
Examples:
Expression Result
name(//b:books/*) b:book
name(//b:book/*) b:title

W3C Documentation reference: Node-Set-Functions
fn:boolean()
The boolean function converts its argument to a boolean as follows:
  • a number is true if and only if it is neither positive or negative zero nor NaN
  • a node-set is true if and only if it is non-empty
  • a string is true if and only if its length is non-zero
  • an object of a type other than the four basic types is converted to a boolean in a way that is dependent on that type
Arguments:
Type Description
object The object to convert to a boolean
Examples:
Expression Result
boolean("Release11") true
boolean("") false

W3C Documentation reference: Boolean-Functions
fn:not()
The not function returns true if its argument is false, and false otherwise.

W3C Documentation reference: Boolean-Functions
fn:true()
The true function returns true.

W3C Documentation reference: Boolean-Functions
fn:false()
The true function returns false.

W3C Documentation reference: Boolean-Functions
fn:lang()
The lang function returns true or false depending on whether the language of the context node as specified by xml:lang attributes is the same as or is a sublanguage of the language specified by the argument string. The language of the context node is determined by the value of the xml:lang attribute on the context node, or, if the context node has no xml:lang attribute, by the value of the xml:lang attribute on the nearest ancestor of the context node that has an xml:lang attribute. If there is no such attribute, then lang returns false. If there is such an attribute, then lang returns true if the attribute value is equal to the argument ignoring case, or if there is some suffix starting with - such that the attribute value is equal to the argument ignoring that suffix of the attribute value and ignoring case.
Arguments:
Type Description
string Language that will be looked for in context node
Examples: Look W3C documentation

W3C Documentation reference: Boolean-Functions
fn:string()
The string function converts an object to a string as follows: A node-set is converted to a string by returning the string-value of the node in the node-set that is first in document order. If the node-set is empty, an empty string is returned.
Arguments:
Type Description
object The object to convert to a string
Examples:
Expression Result
string(10) true

W3C Documentation reference: String-Functions
fn:concat()
The concat function returns the concatenation of its arguments.
Arguments:
Type Description
string* Strings to concatenate
Examples:
Expression Result
concat("Release", 11) Release11

W3C Documentation reference: String-Functions
fn:starts-with()
The concat function returns the concatenation of its arguments.
Arguments:
Type Description
string
string The object to convert to a string
Examples:
Expression Result
concat("Release", 11) Release11

W3C Documentation reference: String-Functions
fn:number()
The number function converts its argument to a number as follows:
  • a string that consists of optional whitespace followed by an optional minus sign followed by a Number followed by whitespace is converted to the IEEE 754 number that is nearest (according to the IEEE 754 round-to-nearest rule) to the mathematical value represented by the string; any other string is converted to NaN
  • boolean true is converted to 1; boolean false is converted to 0
  • a node-set is first converted to a string as if by a call to the string function and then converted in the same way as a string argument
  • an object of a type other than the four basic types is converted to a number in a way that is dependent on that type
Arguments:
Type Description
object The object to convert to a number
Examples:
Expression Result
number(10) 10
number("") NaN

W3C Documentation reference
fn:sum()
The sum function returns the sum, for each node in the argument node-set, of the result of converting the string-values of the node to a number.
Arguments:
Type Description
node-set Node set to sum
Examples:
Expression Result
sum(/l:library/l:readerList/p:person/p:readerID) 12444

W3C Documentation reference
fn:floor()
The floor function returns the largest (closest to positive infinity) number that is not greater than the argument and that is an integer.
Arguments:
Type Description
node-set Node set to sum
Examples:
Expression Result
floor(3.1) 4
floor(3.9) 4
floor(3.5) 4

W3C Documentation reference
fn:ceiling()
The ceiling function returns the smallest (closest to negative infinity) number that is not less than the argument and that is an integer.
Arguments:
Type Description
node-set Node set to sum
Examples:
Expression Result
floor(3.1) 3
floor(3.9) 3
floor(3.5) 3

W3C Documentation reference
fn:round()
The round function returns the number that is closest to the argument and that is an integer. If there are two such numbers, then the one that is closest to positive infinity is returned. If the argument is NaN, then NaN is returned. If the argument is positive infinity, then positive infinity is returned. If the argument is negative infinity, then negative infinity is returned. If the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned. If the argument is less than zero, but greater than or equal to -0.5, then negative zero is returned.

NOTE

For these last two cases, the result of calling the round function is not the same as the result of adding 0.5 and then calling the floor function.
Arguments:
Type Description
node-set Node set to sum
Examples:
Expression Result
floor(3.1) 3
floor(3.9) 4
floor(3.5) 3

W3C Documentation reference
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.
If the argument is omitted, it defaults to the context item (.). The behavior of the function if the argument is omitted is exactly the same as if the context item had been passed as the argument.
The following errors may be raised: if the context item is undefined [err:XPDY0002]XP; if the context item is not a node [err:XPTY0004]XP.
If the argument is supplied and is the empty sequence, the function returns the zero-length string.
If the target node has no name (that is, if it is a document node, a comment, a text node, or a namespace binding having no name), the function returns the zero-length string.
Otherwise, the value returned is fn:string(fn:node-name($arg)).

Arguments:
Type Description
node? Node to display name.
Return type: xs:string

Examples:
Query Result
name(/l:library) l:library

W3C Documentation reference
fn:local-name()
Returns the local part of the name of $arg as an xs:string that will either be the zero-length string or will have the lexical form of an xs:NCName.
If the argument is omitted, it defaults to the context item (.). The behavior of the function if the argument is omitted is exactly the same as if the context item had been passed as the argument.
The following errors may be raised: if the context item is undefined [err:XPDY0002]XP; if the context item is not a node [err:XPTY0004]XP.
If the argument is supplied and is the empty sequence, the function returns the zero-length string.
If the target node has no name (that is, if it is a document node, a comment, or a text node), the function returns the zero-length string.
Otherwise, the value returned will be the local part of the expanded-QName of the target node (as determined by the dm:node-name accessor in Section 5.11 node-name Accessor). This will be an xs:string whose lexical form is an xs:NCName.

Arguments:
Type Description
node? Node to display local-name.
Return type: xs:string

Examples:
Query Result
name(/l:library) library

W3C Documentation reference
fn:nilled()
Returns an xs:boolean indicating whether the argument node is "nilled". If the argument is not an element node, returns the empty sequence. If the argument is the empty sequence, returns the empty sequence.

Arguments:
Type Description
node? Node to test.
Return type: xs:boolean?

Examples:
Query Result
nilled(/l:library) false

W3C Documentation reference
fn:base-uri()
Returns the value of the base-uri URI property for $arg as defined by the accessor function dm:base-uri() for that kind of node in Section 5.2 base-uri AccessorDM. If $arg is not specified, the behavior is identical to calling the function with the context item (.) as argument. The following errors may be raised: if the context item is undefined [err:XPDY0002]XP; if the context item is not a node [err:XPTY0004]XP.
If $arg is the empty sequence, the empty sequence is returned.
Document, element and processing-instruction nodes have a base-uri property which may be empty. The base-uri property of all other node types is the empty sequence. The value of the base-uri property is returned if it exists and is not empty. Otherwise, if the node has a parent, the value of dm:base-uri() applied to its parent is returned, recursively. If the node does not have a parent, or if the recursive ascent up the ancestor chain encounters a node whose base-uri property is empty and it does not have a parent, the empty sequence is returned.

Arguments:
Type Description
node? Node to find base URI of.
Return type: xs:anyURI?

Examples:
Query Result
base-uri(/l:library/l:libraryName) <empty sequence>

W3C Documentation reference
fn:document-uri()
Returns the value of the document-uri property for $arg as defined by the dm:document-uri accessor function defined in Section 6.1.2 AccessorsDM.
If $arg is the empty sequence, the empty sequence is returned.
Returns the empty sequence if the node is not a document node. Otherwise, returns the value of the dm:document-uri accessor of the document node.
In the case of a document node $D returned by the fn:doc function, or a document node at the root of a tree containing a node returned by the fn:collection function, it will always be true that either fn:document-uri($D) returns the empty sequence, or that the following expression is true: fn:doc(fn:document-uri($D)) is $D. It is implementation-defined whether this guarantee also holds for document nodes obtained by other means, for example a document node passed as the initial context node of a query or transformation.

Arguments:
Type Description
node? Node which document-uri value needs to be returned.
Return type: xs:anyURI?

Examples:
Query Result
document-uri(/l:library/l:libraryName) <empty sequence>
document-uri(/library/fiction:book[1]) http://example.com/library.xml (assuming the document URI of the first fiction:book element is "http://example.com/library.xml")
document-uri(/library) http://example.com/library.xml (assuming the document URI of the library element is "http://example.com/library.xml")

W3C Documentation reference
fn:lang()
This function tests whether the language of $node, or the context item 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 $testlang. The behavior of the function if the second argument is omitted is exactly the same as if the context item (.) had been passed as the second argument. The language of the argument node, or the context item if the second argument is omitted, is determined by the value of the xml:lang attribute on the node, or, if the node has no such attribute, by the value of the xml:lang attribute on the nearest ancestor of the node that has an xml:lang attribute. If there is no such ancestor, then the function returns false

Arguments:
Type Description
xs:string? $testlang
node() $node (Optional)
Return type: xs:boolean?

Examples: Look W3C documentation below.
W3C Documentation reference
fn:root()
Returns the root of the tree to which $arg belongs. This will usually, but not necessarily, be a document node.
If $arg is the empty sequence, the empty sequence is returned.
If $arg is a document node, $arg is returned.
If the function is called without an argument, the context item (.) is used as the default argument. The behavior of the function if the argument is omitted is exactly the same as if the context item had been passed as the argument.
The following errors may be raised: if the context item is undefined [err:XPDY0002]; if the context item is not a node [err:XPTY0004].

Arguments:
Type Description
node() $arg (Optional)
Return type: node()?

Examples:
Query Result
root() <l:library>[...]</l:library>

W3C Documentation reference
fn:count()
Returns the number of items in the value of $arg. Returns 0 if $arg is the empty sequence.

Arguments:
Type Description
item()* $arg
Return type: xs:integer

Examples:
Query Result
count(/l:library/l:readerList/p:person) 2
count(/l:library/l:writers) 0

W3C Documentation reference
fn:avg()
Returns the number of items in the value of $arg. Returns 0 if $arg is the empty sequence.

Arguments:
Type Description
xs:anyAtomicType* $arg
Return type: xs:anyAtomicType

Examples:
Query Result
avg(/l:library/l:readerList/p:person/p:readerID) 6222

W3C Documentation reference
fn:max()
Selects an item from the input sequence $arg whose value is greater than or equal to the value of every other item in the input sequence. If there are two or more such items, then the specific item whose value is returned is ·implementation dependent·.

Arguments:
Type Description
xs:anyAtomicType* $arg
xs:string $collation (Optional)
Return type: xs:anyAtomicType?

Examples:
Query Result
max((3,4,5)) 5
max((5, 5.0e0)) 5.0e0

W3C Documentation reference
fn:min()
Selects an item from the input sequence $arg whose value is less than or equal to the value of every other item in the input sequence. If there are two or more such items, then the specific item whose value is returned is ·implementation dependent·.

Arguments:
Type Description
xs:anyAtomicType* $arg
xs:string $collation (Optional)
Return type: xs:anyAtomicType?

Examples:
Query Result
min((3,4,5)) 3
min((5, 5.0e0)) 5.0e0

W3C Documentation reference
fn:sum()
Returns a value obtained by adding together the values in $arg. If $zero is not specified, then the value returned for an empty sequence is the xs:integer value 0. If $zero is specified, then the value returned for an empty sequence is $zero.
Any values of type xs:untypedAtomic in $arg are cast to xs:double. The items in the resulting sequence may be reordered in an arbitrary order. The resulting sequence is referred to below as the converted sequence.

Arguments:
Type Description
xs:anyAtomicType* $arg
xs:anyAtomicType? $zero (Optional)
Return type: xs:anyAtomicType?

Examples:
Query Result
sum(/l:library/l:readerList/p:person/p:readerID) 12444

W3C Documentation reference
fn:boolean()
Computes the effective boolean value of the sequence $arg. See Section 2.4.3 Effective Boolean ValueXP
If $arg is the empty sequence, fn:boolean returns false.
If $arg is a sequence whose first item is a node, fn:boolean returns true.
If $arg is a singleton value of type xs:boolean or a derived from xs:boolean, fn:boolean returns $arg.
If $arg is a singleton value of type xs:string or a type derived from xs:string, xs:anyURI or a type derived from xs:anyURI or xs:untypedAtomic, fn:boolean returns false if the operand value has zero length; otherwise it returns true.
If $arg is a singleton value of any numeric type or a type derived from a numeric type, fn:boolean returns false if the operand value is NaN or is numerically equal to zero; otherwise it returns true. In all other cases, fn:boolean raises a type error [err:FORG0006].
The static semantics of this function are described in Section 7.2.4 The fn:boolean and fn:not functionsFS.

Arguments:
Type Description
item()* $arg
Return type: xs:boolean?

Examples:
Query Result
boolean("/l:library") true
boolean(0) false
boolean(()) false

W3C Documentation reference
fn:true()
Returns the xs:boolean value true. Equivalent to xs:boolean("1").

Return type: xs:boolean

Examples:
Expression Result
true() true

W3C Documentation reference
fn:false()
Returns the xs:boolean value false. Equivalent to xs:boolean("0").

Return type: xs:boolean

Examples:
Expression Result
false() false

W3C Documentation reference
fn:not()
$arg is first reduced to an effective boolean value by applying the fn:boolean() function. Returns true if the effective boolean value is false, and false if the effective boolean value is true.

Arguments and return type:
Type Description
item $arg
Return type: xs:boolean

Examples:
Expression Result
not(false()) true
not(true()) false

W3C Documentation reference
fn:string(object)
Returns the value of $arg represented as a xs:string. If no argument is supplied, the context item (.) is used as the default argument. The behavior of the function if the argument is omitted is exactly the same as if the context item had been passed as the argument.
If the context item is undefined, error [err:XPDY0002]XP is raised.
If $arg is the empty sequence, the zero-length string is returned.
If $arg is a node, the function returns the string-value of the node, as obtained using the dm:string-value accessor defined in the Section 5.13 string-value AccessorDM.
If $arg is an atomic value, then the function returns the same string as is returned by the expression " $arg cast as xs:string " (see 17 Casting).
Arguments and return type:
Type Description
string The object to convert to a string
Return type: xs:string

Examples:
Expression Result
string((1<0)) false
string(.11) 0.11

W3C Documentation reference
fn:codepoints-to-string()
Creates an xs:string from a sequence of The Unicode Standard code points. Returns the zero-length string if $arg is the empty sequence. If any of the code points in $arg is not a legal XML character, an error is raised [err:FOCH0001].
Arguments and return type:
Type Description
xs:integer* $arg
Return type: xs:string

Examples:
Expression Result
codepoints-to-string((2309, 2358, 2378, 2325)) अशॊक
codepoints-to-string((40, 32, 865, 176, 32, 860, 662, 32, 865, 176, 41)) ( ͡° ͜ʖ ͡°)

W3C Documentation reference
fn:string-to-codepoints()
Returns the sequence of The Unicode Standard code points that constitute an xs:string. If $arg is a zero-length string or the empty sequence, the empty sequence is returned.
Arguments and return type:
Type Description
xs:string* $arg
Return type: xs:integer*

Examples:
Expression Result
string-to-codepoints("Thérèse") (84, 104, 233, 114, 232, 115, 101)

W3C Documentation reference
fn:compare()
Returns -1, 0, or 1, depending on whether the value of the $comparand1 is respectively less than, equal to, or greater than the value of $comparand2, according to the rules of the collation that is used.
The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations.
If either argument is the empty sequence, the result is the empty sequence.
This function, invoked with the first signature, backs up the "eq", "ne", "gt", "lt", "le" and "ge" operators on string values.
Arguments and return type:
Type Description
xs:string? $comparand1
xs:string? $comparand2
xs:string $collation (Optional)
Return type: xs:integer*

Examples:
Expression Result
compare('abc', 'abc') 0
compare('abc', 'acc') -1
compare('abc', 'acc') 1

W3C Documentation reference
fn:codepoint-equal()
Returns true or false depending on whether the value of $comparand1 is equal to the value of $comparand2, according to the Unicode code point collation.
If either argument is the empty sequence, the result is the empty sequence.
Arguments and return type:
Type Description
xs:string? $comparand1
xs:string? $comparand2
Return type: xs:boolean?

Examples:
Expression Result
codepoint-equal("asdf", "asdf") true
codepoint-equal("asdf", "asdf ") false

W3C Documentation reference
fn:concat()
Accepts two or more xs:anyAtomicType arguments and casts them to xs:string. Returns the xs:string that is the concatenation of the values of its arguments after conversion. If any of the arguments is the empty sequence, the argument is treated as the zero-length string.
The fn:concat function is specified to allow two or more arguments, which are concatenated together. This is the only function specified in this document that allows a variable number of arguments. This capability is retained for compatibility with [XML Path Language (XPath) Version 1.0].
Arguments and return type:
Type Description
xs:anyAtomicType? $arg1
xs:anyAtomicType? $arg2
xs:anyAtomicType? $arg... (Optional)
Return type: xs:string

Examples:
Expression Result
concat('un', 'grateful') ungrateful
concat('Thy ', (), 'old ', "groans", "", ' ring', ' yet', ' in', ' my', ' ancient',' ears.') Thy old groans ring yet in my ancient ears.
fn:concat('Ciao!',()) Ciao!

W3C Documentation reference
fn:string-join()
Returns a xs:string created by concatenating the members of the $arg1 sequence using $arg2 as a separator. If the value of $arg2 is the zero-length string, then the members of $arg1 are concatenated without a separator.
If the value of $arg1 is the empty sequence, the zero-length string is returned.
Arguments and return type:
Type Description
xs:string* $arg1
xs:string $arg2
Return type: xs:string

Examples:
Expression Result
string-join(('Now', 'is', 'the', 'time', '...'), ' ') Now is the time ...
string-join(('Blow, ', 'blow, ', 'thou ', 'winter ', 'wind!'), '') Blow, blow, thou winter wind!

W3C Documentation reference
fn:substring()
Returns the portion of the value of $sourceString beginning at the position indicated by the value of $startingLoc and continuing for the number of characters indicated by the value of $length. The characters returned do not extend beyond $sourceString. If $startingLoc is zero or negative, only those characters in positions greater than zero are returned.
More specifically, the three argument version of the function returns the characters in $sourceString whose position $p obeys:
fn:round($startingLoc) <= $p < fn:round($startingLoc) + fn:round($length)
The two argument version of the function assumes that $length is infinite and returns the characters in $sourceString whose position $p obeys:
fn:round($startingLoc) <= $p < fn:round(INF)
In the above computations, the rules for op:numeric-less-than() and op:numeric-greater-than() apply.
If the value of $sourceString is the empty sequence, the zero-length string is returned.
Note:
The first character of a string is located at position 1, not position 0.
Arguments and return type:
Type Description
xs:string? $sourceString
xs:double $startingLoc
xs:double $length (Optional)
Return type: xs:string

Examples:
Expression Result
substring("motor car", 6) " car"
substring("metadata", 4, 3) ada

W3C Documentation reference
fn:string-length()
Returns an xs:integer equal to the length in characters of the value of $arg.
If the value of $arg is the empty sequence, the xs:integer 0 is returned.
If no argument is supplied, $arg defaults to the string value (calculated using fn:string()) of the context item (.). If no argument is supplied and the context item is undefined an error is raised: [err:XPDY0002].
Arguments and return type:
Type Description
xs:string? $arg (Optional)
Return type: xs:integer

Examples:
Expression Result
string-length("Harp not on that string, madam; that is past.") 45
string-length(()) 0

W3C Documentation reference
fn:normalize-space()
Returns the value of $arg with whitespace normalized by stripping leading and trailing whitespace and replacing sequences of one or more than one whitespace character with a single space, #x20.
If the value of $arg is the empty sequence, returns the zero-length string.
If no argument is supplied, then $arg defaults to the string value (calculated using fn:string()) of the context item (.). If no argument is supplied and the context item is undefined an error is raised: [err:XPDY0002].
Arguments and return type:
Type Description
xs:string? $arg (Optional)
Return type: xs:string

Examples:
Expression Result
normalize-space(" The wealthy curled darlings of our nation. ") The wealthy curled darlings of our nation.
normalize-space(()) ""

W3C Documentation reference
fn:normalize-unicode()
Returns the value of $arg normalized according to the normalization criteria for a normalization form identified by the value of $normalizationForm. The effective value of the $normalizationForm is computed by removing leading and trailing blanks, if present, and converting to upper case.
If the value of $arg is the empty sequence, returns the zero-length string.
Arguments and return type:
Type Description
xs:string? $arg
xs:string $normalizationForm (Optional)
Return type: xs:string

Examples:
Expression Result
normalize-unicode("test ") test

W3C Documentation reference
fn:upper-case()
Returns the value of $arg after translating every character to its upper-case correspondent as defined in the appropriate case mappings section in the Unicode standard [The Unicode Standard]. For versions of Unicode beginning with the 2.1.8 update, only locale-insensitive case mappings should be applied. Beginning with version 3.2.0 (and likely future versions) of Unicode, precise mappings are described in default case operations, which are full case mappings in the absence of tailoring for particular languages and environments. Every lower-case character that does not have an upper-case correspondent, as well as every upper-case character, is included in the returned value in its original form.
If the value of $arg is the empty sequence, the zero-length string is returned.
Arguments and return type:
Type Description
xs:string? $arg
Return type: xs:string

Examples:
Expression Result
upper-case("abCd0") ABCD0

W3C Documentation reference
fn:lower-case()
Returns the value of $arg after translating every character to its lower-case correspondent as defined in the appropriate case mappings section in the Unicode standard [The Unicode Standard]. For versions of Unicode beginning with the 2.1.8 update, only locale-insensitive case mappings should be applied. Beginning with version 3.2.0 (and likely future versions) of Unicode, precise mappings are described in default case operations, which are full case mappings in the absence of tailoring for particular languages and environments. Every upper-case character that does not have a lower-case correspondent, as well as every lower-case character, is included in the returned value in its original form.
If the value of $arg is the empty sequence, the zero-length string is returned.
Arguments and return type:
Type Description
xs:string? $arg
Return type: xs:string

Examples:
Expression Result
lower-case("abCd0") abcd0

W3C Documentation reference
fn:translate()
Returns the value of $arg modified so that every character in the value of $arg that occurs at some position N in the value of $mapString has been replaced by the character that occurs at position N in the value of $transString.
If the value of $arg is the empty sequence, the zero-length string is returned.
Every character in the value of $arg that does not appear in the value of $mapString is unchanged.
Every character in the value of $arg that appears at some position M in the value of $mapString, where the value of $transString is less than M characters in length, is omitted from the returned value. If $mapString is the zero-length string $arg is returned.
If a character occurs more than once in $mapString, then the first occurrence determines the replacement character. If $transString is longer than $mapString, the excess characters are ignored.
Arguments and return type:
Type Description
xs:string? $arg
xs:string $mapString
xs:string $mapString
Return type: xs:string

Examples:
Expression Result
translate("bar","abc","ABC") BAr
translate("--aaa--","abc-","ABC") AAA
translate("abcdabc", "abc", "AB") ABdAB

W3C Documentation reference
fn:encode-for-uri()
This function encodes reserved characters in an xs:string that is intended to be used in the path segment of a URI. It is invertible but not idempotent. This function applies the URI escaping rules defined in section 2 of [RFC 3986] to the xs:string supplied as $uri-part. The effect of the function is to escape reserved characters. Each such character in the string is replaced with its percent-encoded form as described in [RFC 3986].
If $uri-part is the empty sequence, returns the zero-length string.
All characters are escaped except those identified as "unreserved" by [RFC 3986], that is the upper- and lower-case letters A-Z, the digits 0-9, HYPHEN-MINUS ("-"), LOW LINE ("_"), FULL STOP ".", and TILDE "~".
Note that this function escapes URI delimiters and therefore cannot be used indiscriminately to encode "invalid" characters in a path segment.
Since [RFC 3986] recommends that, for consistency, URI producers and normalizers should use uppercase hexadecimal digits for all percent-encodings, this function must always generate hexadecimal values using the upper-case letters A-F.
Arguments and return type:
Type Description
xs:string? $uri-part
Return type: xs:string

Examples:
Expression Result
encode-for-uri("https://www.google.com") "https%3A%2F%2Fwww.
google.com"
concat("http://www.example.com/", encode-for-uri("~bébé")) http://www.example.com/
~b%C3%A9b%C3%A9
concat("http://www.example.com/", encode-for-uri("100% organic")) http://www.example.com/
100%25%20organic

W3C Documentation reference
fn:iri-to-uri()
This function converts an xs:string containing an IRI into a URI according to the rules spelled out in Section 3.1 of [RFC 3987]. It is idempotent but not invertible.
If $iri contains a character that is invalid in an IRI, such as the space character (see note below), the invalid character is replaced by its percent-encoded form as described in [RFC 3986] before the conversion is performed.
If $iri is the empty sequence, returns the zero-length string.
Arguments and return type:
Type Description
xs:string? $iri
Return type: xs:string

Examples:
Expression Result
iri-to-uri ("http://www.example.com/00/Weather/CA/Los%20Angeles#ocean") "http://www.example.com/00/
Weather/CA/Los%20Angeles#ocean"
iri-to-uri ("http://www.example.com/~bébé") http://www.example.com/
~b%C3%A9b%C3%A9

W3C Documentation reference
fn:escape-html-uri()
This function escapes all characters except printable characters of the US-ASCII coded character set, specifically the octets ranging from 32 to 126 (decimal). The effect of the function is to escape a URI in the manner html user agents handle attribute values that expect URIs. Each character in $uri to be escaped is replaced by an escape sequence, which is formed by encoding the character as a sequence of octets in UTF-8, and then representing each of these octets in the form %HH, where HH is the hexadecimal representation of the octet. This function must always generate hexadecimal values using the upper-case letters A-F.
If $uri is the empty sequence, returns the zero-length string.

Note:

The behavior of this function corresponds to the recommended handling of non-ASCII characters in URI attribute values as described in [HTML 4.0] Appendix B.2.1.

Arguments and return type:
Type Description
xs:string? $uri
Return type: xs:string

Examples:
Expression Result
escape-html-uri("http://www.example.com/00/Weather/CA/Los Angeles#ocean") http://www.example.com/00/Weather/CA/Los Angeles#ocean

W3C Documentation reference
fn:contains()
Returns an xs:boolean indicating whether or not the value of $arg1 contains (at the beginning, at the end, or anywhere within) at least one sequence of collation units that provides a minimal match to the collation units in the value of $arg2, according to the collation that is used. If the value of $arg1 or $arg2 is the empty sequence, or contains only ignorable collation units, it is interpreted as the zero-length string.
If the value of $arg2 is the zero-length string, then the function returns true.
If the value of $arg1 is the zero-length string, the function returns false.
The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations. If the specified collation does not support collation units an error ·may· be raised [err:FOCH0004].

Arguments and return type:
Type Description
xs:string? $arg1
xs:string? $arg2
xs:string? $collation (Optional)
Return type: xs:boolean

Examples:
Expression Result
contains( "tattoo", "tat") true
contains( "tattoo", "ttt") false
contains ( "", ()) true

W3C Documentation reference
fn:starts-with()
Returns an xs:boolean indicating whether or not the value of $arg1 starts with a sequence of collation units that provides a match to the collation units of $arg2 according to the collation that is used. If the value of $arg1 or $arg2 is the empty sequence, or contains only ignorable collation units, it is interpreted as the zero-length string.
If the value of $arg2 is the zero-length string, then the function returns true. If the value of $arg1 is the zero-length string and the value of $arg2 is not the zero-length string, then the function returns false.
The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations. If the specified collation does not support collation units an error ·may· be raised [err:FOCH0004].

Arguments and return type:
Type Description
xs:string? $arg1
xs:string? $arg2
xs:string? $collation (Optional)
Return type: xs:boolean

Examples:
Expression Result
starts-with( "tattoo", "tat") true
starts-with( "tattoo", "ttt") false
starts-with ( "", ()) true

W3C Documentation reference
fn:ends-with()
Returns an xs:boolean indicating whether or not the value of $arg1 starts with a sequence of collation units that provides a match to the collation units of $arg2 according to the collation that is used.
If the value of $arg1 or $arg2 is the empty sequence, or contains only ignorable collation units, it is interpreted as the zero-length string.
If the value of $arg2 is the zero-length string, then the function returns true. If the value of $arg1 is the zero-length string and the value of $arg2 is not the zero-length string, then the function returns false.
The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations. If the specified collation does not support collation units an error ·may· be raised [err:FOCH0004].

Arguments and return type:
Type Description
xs:string? $arg1
xs:string? $arg2
xs:string? $collation (Optional)
Return type: xs:boolean

Examples:
Expression Result
ends-with( "tattoo", "too") true
ends-with( "tattoo", "tatoo") false
ends-with ((), ()) true

W3C Documentation reference
fn:substring-before()
Returns the substring of the value of $arg1 that precedes in the value of $arg1 the first occurrence of a sequence of collation units that provides a minimal match to the collation units of $arg2 according to the collation that is used.
If the value of $arg1 or $arg2 is the empty sequence, or contains only ignorable collation units, it is interpreted as the zero-length string.
If the value of $arg2 is the zero-length string, then the function returns the zero-length string.
If the value of $arg1 does not contain a string that is equal to the value of $arg2, then the function returns the zero-length string.
The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations If the specified collation does not support collation units an error ·may· be raised [err:FOCH0004].

Arguments and return type:
Type Description
xs:string? $arg1
xs:string? $arg2
xs:string? $collation (Optional)
Return type: xs:string

Examples:
Expression Result
substring-before( "tattoo", "too") tat
substring-before( "tattoo", "tat") <empty string>

W3C Documentation reference
fn:substring-after()
Returns the substring of the value of $arg1 that follows in the value of $arg1 the first occurrence of a sequence of collation units that provides a minimal match to the collation units of $arg2 according to the collation that is used.
If the value of $arg1 or $arg2 is the empty sequence, or contains only ignorable collation units, it is interpreted as the zero-length string.
If the value of $arg2 is the zero-length string, then the function returns the value of $arg1.
If the value of $arg1 does not contain a string that is equal to the value of $arg2, then the function returns the zero-length string.
The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations If the specified collation does not support collation units an error ·may· be raised [err:FOCH0004].

Arguments and return type:
Type Description
xs:string? $arg1
xs:string? $arg2
xs:string? $collation (Optional)
Return type: xs:string

Examples:
Expression Result
substring-after( "tattoo", "too") <empty string>
substring-after( "tattoo", "tat") too

W3C Documentation reference
fn:matches()
The function returns true if $input matches the regular expression supplied as $pattern as influenced by the value of $flags, if present; otherwise, it returns false.
The effect of calling the first version of this function (omitting the argument $flags) is the same as the effect of calling the second version with the $flags argument set to a zero-length string. Flags are defined in 7.6.1.1 Flags.
If $input is the empty sequence, it is interpreted as the zero-length string.
Unless the metacharacters ^ and $ are used as anchors, the string is considered to match the pattern if any substring matches the pattern. But if anchors are used, the anchors must match the start/end of the string (in string mode), or the start/end of a line (in multiline mode).
An error is raised [err:FORX0002] if the value of $pattern is invalid according to the rules described in section 7.6.1 Regular Expression Syntax.
An error is raised [err:FORX0001] if the value of $flags is invalid according to the rules described in section 7.6.1 Regular Expression Syntax.

Arguments and return type:
Type Description
xs:string? $input
xs:string $pattern
xs:string $flags (Optional)
Return type: xs:boolean

Examples:
Expression Result
matches("abracadabra", "bra") true
matches("abracadabra", "^a.*a$") false

W3C Documentation reference
fn:replace()
The function returns the xs:string that is obtained by replacing each non-overlapping substring of $input that matches the given $pattern with an occurrence of the $replacement string.
The effect of calling the first version of this function (omitting the argument $flags) is the same as the effect of calling the second version with the $flags argument set to a zero-length string. Flags are defined in 7.6.1.1 Flags.
The $flags argument is interpreted in the same manner as for the fn:matches() function.
If $input is the empty sequence, it is interpreted as the zero-length string.
If two overlapping substrings of $input both match the $pattern, then only the
first one (that is, the one whose first character comes first in the $input string) is replaced. Within the $replacement string, a variable $N may be used to refer to the substring captured by the Nth parenthesized sub-expression in the regular expression. For each match of the pattern, these variables are assigned the value of the content matched by the relevant sub-expression, and the modified replacement string is then substituted for the characters in $input that matched the pattern. $0 refers to the substring captured by the regular expression as a whole.

Arguments and return type:
Type Description
xs:string? $input
xs:string $pattern
xs:string $replacement
xs:string $flags (Optional)
Return type: xs:string

Examples:
Expression Result
replace("abracadabra", "bra", "*") a*cada*
replace("abracadabra", "a.*a", "*") *
replace("AAAA", "A+", "b") b

W3C Documentation reference
fn:tokenize()
This function breaks the $input string into a sequence of strings, treating any substring that matches $pattern as a separator. The separators themselves are not returned.
The effect of calling the first version of this function (omitting the argument $flags) is the same as the effect of calling the second version with the $flags argument set to a zero-length string. Flags are defined in 7.6.1.1 Flags.
The $flags argument is interpreted in the same way as for the fn:matches() function.
If $input is the empty sequence, or if $input is the zero-length string, the result is the empty sequence.
If the supplied $pattern matches a zero-length string, that is, if fn:matches("", $pattern, $flags) returns true, then an error is raised: [err:FORX0003].
If a separator occurs at the start of the $input string, the result sequence will start with a zero-length string. Zero-length strings will also occur in the result sequence if a separator occurs at the end of the $input string, or if two adjacent substrings match the supplied $pattern.

Arguments and return type:
Type Description
xs:string? $input
xs:string $pattern
xs:string $flags (Optional)
Return type: xs:string*

Examples:
Expression Result
tokenize("The cat sat on the mat", "\s+") ("The", "cat", "sat", "on", "the", "mat")
tokenize("1, 15, 24, 50", ",\s*") ("1", "15", "24", "50")
tokenize("1,15,,24,50,", ",") ("1", "15", "", "24", "50", "")

W3C Documentation reference
fn:number()
Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double
Calling the zero-argument version of the function is defined to give the same result as calling the single-argument version with the context item (.). That is, fn:number() is equivalent to fn:number(.).
If $arg is the empty sequence or if $arg or the context item cannot be converted to an xs:double, the xs:double value NaN is returned. If the context item is undefined an error is raised: [err:XPDY0002]XP.
If $arg is the empty sequence, NaN is returned. Otherwise, $arg, or the context item after atomization, is converted to an xs:double following the rules of 17.1.3.2 Casting to xs:double. If the conversion to xs:double fails, the xs:double value NaN is returned.

Arguments:
Type Description
xs:anyAtomicType? Value to convert to number
Return type: xs:double

W3C Documentation reference
fn:abs()
Returns the absolute value of $arg. If $arg is negative returns -$arg otherwise returns $arg. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
For xs:float and xs:double arguments, if the argument is positive zero or negative zero, then positive zero is returned. If the argument is positive or negative infinity, positive infinity is returned.
For detailed type semantics, see Section 7.2.3 The fn:abs, fn:ceiling, fn:floor, fn:round, and fn:round-half-to-even functions.

Arguments:
Type Description
numeric? $arg
Return type: numeric?

Examples:
Query Result
abs(-2) 2
abs(2137) 2137

W3C Documentation reference
fn:ceiling()
Returns the smallest (closest to negative infinity) number with no fractional part that is not less than the value of $arg. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
For xs:float and xs:double arguments, if the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned. If the argument is less than zero and greater than -1, negative zero is returned.

Arguments:
Type Description
numeric? $arg
Return type: numeric?

Examples:
Query Result
ceiling(10.5) 11
ceiling(-10.5) -10
ceiling(10.1) 11

W3C Documentation reference
fn:floor()
Returns the largest (closest to positive infinity) number with no fractional part that is not greater than the value of $arg. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
For float and double arguments, if the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned.

Arguments:
Type Description
numeric? $arg
Return type: numeric?

Examples:
Query Result
floor(10.5) 10
floor(-10.5) -11
floor(10.8) 10

W3C Documentation reference
fn:round()
Returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
For xs:float and xs:double arguments, if the argument is positive infinity, then positive infinity is returned. If the argument is negative infinity, then negative infinity is returned. If the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned. If the argument is less than zero, but greater than or equal to -0.5, then negative zero is returned. In the cases where positive zero or negative zero is returned, negative zero or positive zero may be returned as [XML Schema Part 2: Datatypes Second Edition] does not distinguish between the values positive zero and negative zero.
For the last two cases, note that the result is not the same as fn:floor(x+0.5).

Arguments:
Type Description
numeric? $arg
Return type: numeric?

Examples:
Query Result
round(10.5) 11
round(10.4999) 10
round(-10.5) -10

W3C Documentation reference
fn:round-half-to-even()
The value returned is the nearest (that is, numerically closest) value to $arg that is a multiple of ten to the power of minus $precision. If two such values are equally near (e.g. if the fractional part in $arg is exactly .500...), the function returns the one whose least significant digit is even.
If the type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
The first signature of this function produces the same result as the second signature with $precision=0.
For arguments of type xs:float and xs:double, if the argument is NaN, positive or negative zero, or positive or negative infinity, then the result is the same as the argument. In all other cases, the argument is cast to xs:decimal, the function is applied to this xs:decimal value, and the resulting xs:decimal is cast back to xs:float or xs:double as appropriate to form the function result. If the resulting xs:decimal value is zero, then positive or negative zero is returned according to the sign of the original argument.
Note that the process of casting to xs:decimal may result in an error [err:FOCA0001].
If $arg is of type xs:float or xs:double, rounding occurs on the value of the mantissa computed with exponent = 0.

Arguments:
Type Description
numeric? $arg
numeric? $precision (Optional)
Return type: numeric?

Examples:
Query Result
round-half-to-even(0.5) 0
round-half-to-even(1.5) 2
round-half-to-even(2.5) 2
round-half-to-even(2.6) 3

W3C Documentation reference
fn:data()
fn:data takes a sequence of items and returns a sequence of atomic values.
The result of fn:data is the sequence of atomic values produced by applying the following rules to each item in $arg:
  • If the item is an atomic value, it is returned.
  • If the item is a node:
    • If the node does not have a typed value an error is raised [err:FOTY0012].
    • Otherwise, fn:data() returns the typed value of the node as defined by the accessor function dm:typed-value in Section 5.15 typed-value AccessorDM.

Arguments:
Type Description
item* Items to convert.
Return type: xs:anyAtomicType*

Examples:
Query Result
data(/l:library/l:readerList/p:person[1]) 7321
Adam
Choke

W3C Documentation reference
fn:index-of()
Returns the root of the tree to which $arg belongs. This will usually, but not necessarily, be a document node.
If $arg is the empty sequence, the empty sequence is returned.
If $arg is a document node, $arg is returned.
If the function is called without an argument, the context item (.) is used as the default argument. The behavior of the function if the argument is omitted is exactly the same as if the context item had been passed as the argument.
The following errors may be raised: if the context item is undefined [err:XPDY0002]; if the context item is not a node [err:XPTY0004].

Arguments:
Type Description
xs:anyAtomicType $seqParam
xs:anyAtomicType $srchParam
xs:string $collation (Optional)
Return type: xs:integer*

Examples:
Query Result
index-of((10, 20, 30, 40), 35) ()
index-of((10, 20, 30, 30, 20, 10), 20) (2, 5)
index-of(("a", "sport", "and", "a", "pastime"), "a") (1, 4)

W3C Documentation reference
fn:empty()
If the value of $arg is the empty sequence, the function returns true; otherwise, the function returns false.

Arguments:
Type Description
item()* $arg
Return type: xs:boolean

Examples:
Query Result
empty(fn:remove(("hello", "world"), 1)) false

W3C Documentation reference
fn:exists()
If the value of $arg is not the empty sequence, the function returns true; otherwise, the function returns false.

Arguments:
Type Description
item()* $arg
Return type: xs:boolean

Examples:
Query Result
exists(fn:remove(("hello"), 1)) true

W3C Documentation reference
fn:distinct-values()
Returns the sequence that results from removing from $arg all but one of a set of values that are eq to one other. Values of type xs:untypedAtomic are compared as if they were of type xs:string. Values that cannot be compared, i.e. the eq operator is not defined for their types, are considered to be distinct. The order in which the sequence of values is returned is ·implementation dependent·.

Arguments:
Type Description
xs:anyAtomicType* $arg
xs:string $collation (Optional)
Return type: xs:anyAtomicType*

Examples:
Query Result
distinct-values((1, 2.0, 3, 2)) (1, 3, 2.0)

W3C Documentation reference
fn:insert-before()
Returns a new sequence constructed from the value of $target with the value of $inserts inserted at the position specified by the value of $position. (The value of $target is not affected by the sequence construction.)
If $target is the empty sequence, $inserts is returned. If $inserts is the empty sequence, $target is returned.
The value returned by the function consists of all items of $target whose index is less than $position, followed by all items of $inserts, followed by the remaining elements of $target, in that sequence.
If $position is less than one (1), the first position, the effective value of $position is one (1). If $position is greater than the number of items in $target, then the effective value of $position is equal to the number of items in $target plus 1.

Arguments:
Type Description
item()* $target
xs:integer $position
item()* $inserts
Return type: item()*

Examples:
let $x := ("a", "b", "c")
Query Result
insert-before($x, 0, "z") ("z", "a", "b", "c")
insert-before($x, 1, "z") ("z", "a", "b", "c")
insert-before($x, 2, "z") ("a", "z", "b", "c")

W3C Documentation reference
fn:remove()
Returns a new sequence constructed from the value of $target with the item at the position specified by the value of $position removed.
If $position is less than 1 or greater than the number of items in $target, $target is returned. Otherwise, the value returned by the function consists of all items of $target whose index is less than $position, followed by all items of $target whose index is greater than $position. If $target is the empty sequence, the empty sequence is returned.

Arguments:
Type Description
item()* $target
xs:integer $position
Return type: item()*

Examples:
let $x := ("a", "b", "c")
Query Result
remove($x, 0) ("a", "b", "c")
remove($x, 1) ("b", "c")
remove($x, 6) ("a", "b", "c")

W3C Documentation reference
fn:reverse()
Reverses the order of items in a sequence. If $arg is the empty sequence, the empty sequence is returned.

Arguments:
Type Description
item()* $arg
Return type: item()*

Examples:
let $x := ("a", "b", "c")
Query Result
reverse($x) ("c", "b", "a")
reverse(("hello")) ("hello")
reverse(()) ()

W3C Documentation reference
fn:subsequence()
Returns the contiguous sequence of items in the value of $sourceSeq beginning at the position indicated by the value of $startingLoc and continuing for the number of items indicated by the value of $length. If $sourceSeq is the empty sequence, the empty sequence is returned.
If $startingLoc is zero or negative, the subsequence includes items from the beginning of the $sourceSeq.
If $length is not specified, the subsequence includes items to the end of $sourceSeq.
If $length is greater than the number of items in the value of $sourceSeq following $startingLoc, the subsequence includes items to the end of $sourceSeq.
The first item of a sequence is located at position 1, not position 0.

Arguments:
Type Description
item()* $sourceSeq
xs:double $startingLoc (Optional)
xs:double $length (Optional)
Return type: item()*

Examples:
let $seq = ($item1, $item2, $item3, $item4, ...)
Query Result
subsequence($seq, 4) ($item4, ...)
subsequence($seq, 3, 2) ($item3, $item4)

W3C Documentation reference
fn:unordered()
Returns the items of $sourceSeq in an implementation dependent order.

Arguments:
Type Description
item()* $sourceSeq
Return type: item()*

W3C Documentation reference
fn:zero-or-one()
Returns $arg if it contains zero or one items. Otherwise, raises an error [err:FORG0003].

Arguments:
Type Description
item()* $arg
Return type: item()?

Examples:
Query Result
zero-or-one(("a")) a
zero-or-one(("a", "b")) A sequence of more than one item is not allowed as the first argument of fn:zero-or-one() ("a", "b")

W3C Documentation reference
fn:one-or-more()
Returns $arg if it contains one or more items. Otherwise, raises an error [err:FORG0004].

Arguments:
Type Description
item()* $arg
Return type: item()?

Examples:
Query Result
one-or-more(("a")) a
one-or-more(("a", "b")) a
b

W3C Documentation reference
fn:exactly-one()
Returns $arg if it contains exactly one item. Otherwise, raises an error [err:FORG0005].

Arguments:
Type Description
item()* $arg
Return type: item()?

Examples:
Query Result
exactly-one(("a")) a
exactly-one(("a", "b")) A sequence of more than one item is not allowed as the first argument of fn:exactly-one() ("a", "b")

W3C Documentation reference
fn:deep-equal()
This function assesses whether two sequences are deep-equal to each other. To be deep-equal, they must contain items that are pairwise deep-equal; and for two items to be deep-equal, they must either be atomic values that compare equal, or nodes of the same kind, with the same name, whose children are deep-equal. This is defined in more detail below. The $collation argument identifies a collation which is used at all levels of recursion when strings are compared (but not when names are compared), according to the rules in 7.3.1 Collations.
If the two sequences are both empty, the function returns true.
If the two sequences are of different lengths, the function returns false.
If the two sequences are of the same length, the function returns true if and only if every item in the sequence $parameter1 is deep-equal to the item at the same position in the sequence $parameter2. The rules for deciding whether two items are deep-equal follow. For more in-depth description look into W3C Documentation

Arguments:
Type Description
item()* $parameter1
item()* $parameter2
xs:string $collation (Optional)
Return type: xs:boolean

Examples:
Query Result
deep-equal(/l:library/p:person[0], /l:library/p:person[1]) true
deep-equal(/l:library/p:person[0], /l:library) false

W3C Documentation reference
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 $arg.

Note:

This function does not have the desired effect when searching a document in which elements of type xs:ID are used as identifiers. To preserve backwards compatibility, a new function fn:element-with-id is therefore being introduced; it behaves the same way as fn:id in the case of ID-valued attributes.

Arguments:
Type Description
xs:string* $arg
node()* $node
xs:string $collation (Optional)
Return type: element()*

W3C Documentation reference
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 $arg.

Arguments:
Type Description
xs:string* $arg
node()* $node
xs:string $collation (Optional)
Return type: node()*

W3C Documentation reference
fn:doc()
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 $arg.

Arguments:
Type Description
xs:string $uri
Return type: document-node()?

Examples:
Query Result
doc("test.xml") Contents of test.xml file returned as node

W3C Documentation reference
fn:doc-available()
Retrieves a document using a URI supplied as an xs:string, and returns the corresponding document node.
If $uri is the empty sequence, the result is an empty sequence.
If $uri is not a valid URI, an error may be raised [err:FODC0005].
If $uri is a relative URI reference, it is resolved relative to the value of the base URI property from the static context. The resulting absolute URI is promoted to an xs:string.

Arguments:
Type Description
xs:string $uri
Return type: xs:boolean

Examples:
Query Result
doc("test.xml") true (If document is available)

W3C Documentation reference
fn:collection()
This function takes an xs:string as argument and returns a sequence of nodes obtained by interpreting $arg as an xs:anyURI and resolving it according to the mapping specified in Available collections described in Section C.2 Dynamic Context ComponentsXP. If Available collections provides a mapping from this string to a sequence of nodes, the function returns that sequence. If Available collections maps the string to an empty sequence, then the function returns an empty sequence. If Available collections provides no mapping for the string, an error is raised [err:FODC0004].
If $arg is not specified, the function returns the sequence of the nodes in the default collection in the dynamic context. See Section C.2 Dynamic Context ComponentsXP. If the value of the default collection is undefined an error is raised [err:FODC0002].

Arguments:
Type Description
xs:string? $arg (Optional)
Return type: node()*

Examples:
Query Result
collection("") <empty sequence>

W3C Documentation reference
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 $arg.

Arguments:
Type Description
xs:string? $arg (Optional)
Return type: node()*

W3C Documentation reference
fn:position()
Returns the context position from the dynamic context. (See Section C.2 Dynamic Context ComponentsXP.) If the context item is undefined, an error is raised: [err:XPDY0002]XP.

Return type: xs:integer

Examples:
Query Result
/l:library/l:readerList/position() 1

W3C Documentation reference
fn:last()
Returns the context size from the dynamic context. (See Section C.2 Dynamic Context ComponentsXP.) If the context item is undefined, an error is raised: [err:XPDY0002]XP.

Return type: xs:integer

Examples:
Query Result
/l:library/l:readerList/p:person/last() 2
2

W3C Documentation reference
fn:years-from-duration()
Returns an xs:integer representing the years component in the value of $arg. The result is obtained by casting $arg to an xs:yearMonthDuration (see 17.1.4 Casting to duration types) and then computing the years component as described in 10.3.1.3 Canonical representation.
The result may be negative.
If $arg is an xs:dayTimeDuration returns 0.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:duration? $arg
Return type: xs:integer?

Examples:
Expression Result
years-from-duration(xs:yearMonthDuration("P20Y15M")) 21
years-from-duration(xs:yearMonthDuration("-P15M")) -1
years-from-duration(xs:dayTimeDuration("-P2DT15H")) 0

W3C Documentation reference
fn:months-from-duration()
Returns an xs:integer representing the months component in the value of $arg. The result is obtained by casting $arg to an xs:yearMonthDuration (see 17.1.4 Casting to duration types) and then computing the months component as described in 10.3.1.3 Canonical representation.
The result may be negative.
If $arg is an xs:dayTimeDuration returns 0.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:duration? $arg
Return type: xs:integer?

Examples:
Expression Result
months-from-duration(xs:yearMonthDuration("P20Y15M")) 3
months-from-duration(xs:yearMonthDuration("-P20Y18M")) -6
months-from-duration(xs:dayTimeDuration("-P2DT15H0M0S")) 0

W3C Documentation reference
fn:days-from-duration()
Returns an xs:integer representing the days component in the value of $arg. The result is obtained by casting $arg to an xs:dayTimeDuration (see 17.1.4 Casting to duration types) and then computing the days component as described in 10.3.2.3 Canonical representation.
The result may be negative.
If $arg is an xs:yearMonthDuration returns 0.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:duration? $arg
Return type: xs:integer?

Examples:
Expression Result
days-from-duration(xs:dayTimeDuration("P3DT10H")) 3
days-from-duration(xs:dayTimeDuration("P3DT55H")) 5
days-from-duration(xs:yearMonthDuration("P3Y5M")) 0

W3C Documentation reference
fn:hours-from-duration()
Returns an xs:integer representing the hours component in the value of $arg. The result is obtained by casting $arg to an xs:dayTimeDuration (see 17.1.4 Casting to duration types) and then computing the hours component as described in 10.3.2.3 Canonical representation.
The result may be negative.
If $arg is an xs:yearMonthDuration returns 0.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:duration? $arg
Return type: xs:integer?

Examples:
Expression Result
hours-from-duration(xs:dayTimeDuration("P3DT10H")) 10
hours-from-duration(xs:dayTimeDuration("P3DT12H32M12S")) 12
hours-from-duration(xs:dayTimeDuration("PT123H")) 0

W3C Documentation reference
fn:minutes-from-duration()
Returns an xs:integer representing the minutes component in the value of $arg. The result is obtained by casting $arg to an xs:dayTimeDuration (see 17.1.4 Casting to duration types) and then computing the minutes component as described in 10.3.2.3 Canonical representation. The result may be negative. If $arg is an xs:yearMonthDuration returns 0. If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:duration? $arg
Return type: xs:integer?

Examples:
Expression Result
minutes-from-duration(xs:dayTimeDuration("P3DT10H")) 0
minutes-from-duration(xs:dayTimeDuration("-P5DT12H30M")) -30

W3C Documentation reference
fn:seconds-from-duration()
Returns an xs:decimal representing the seconds component in the value of $arg. The result is obtained by casting $arg to an xs:dayTimeDuration (see 17.1.4 Casting to duration types) and then computing the seconds component as described in 10.3.2.3 Canonical representation.
The result may be negative.
If $arg is an xs:yearMonthDuration returns 0.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:duration? $arg
Return type: xs:decimal?

Examples:
Expression Result
seconds-from-duration(xs:dayTimeDuration("P3DT10H12.5S")) 12.5
seconds-from-duration(xs:dayTimeDuration("-PT256S")) -16.0

W3C Documentation reference
fn:year-from-dateTime()
Returns an xs:integer representing the year component in the localized value of $arg. The result may be negative.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:dateTime? $arg
Return type: xs:integer?

Examples:
Expression Result
year-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) 1999
year-from-dateTime(xs:dateTime("1999-12-31T19:20:00")) 1999
year-from-dateTime(xs:dateTime("1999-12-31T24:00:00")) 2000

W3C Documentation reference
fn:month-from-dateTime()
Returns an xs:integer between 1 and 12, both inclusive, representing the month component in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:dateTime? $arg
Return type: xs:integer?

Examples:
Expression Result
month-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) 5
month-from-dateTime(xs:dateTime("1999-12-31T19:20:00")) 12
month-from-dateTime(xs:dateTime("1999-12-31T24:00:00")) 1

W3C Documentation reference
fn:day-from-dateTime()
Returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:dateTime? $arg
Return type: xs:integer?

Examples:
Expression Result
day-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) 31
day-from-dateTime(xs:dateTime("1999-12-31T19:20:00")) 31
day-from-dateTime(xs:dateTime("1999-12-31T24:00:00")) 1

W3C Documentation reference
fn:hours-from-dateTime()
Returns an xs:integer between 0 and 23, both inclusive, representing the hours component in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:dateTime? $arg
Return type: xs:integer?

Examples:
Expression Result
hours-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) 13
hours-from-dateTime(xs:dateTime("1999-12-31T19:20:00")) 19
hours-from-dateTime(xs:dateTime("1999-12-31T24:00:00")) 0

W3C Documentation reference
fn:minutes-from-dateTime()
Returns an xs:integer value between 0 and 59, both inclusive, representing the minute component in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:dateTime? $arg
Return type: xs:integer?

Examples:
Expression Result
minutes-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) 20
minutes-from-dateTime(xs:dateTime("1999-05-31T13:30:00+05:30")) 30

W3C Documentation reference
fn:seconds-from-dateTime()
Returns an xs:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:dateTime? $arg
Return type: xs:decimal?

Examples:
Expression Result
seconds-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) 0

W3C Documentation reference
fn:timezone-from-dateTime()
Returns an xs:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:dateTime? $arg
Return type: xs:dayTimeDuration?

Examples:
Expression Result
timezone-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) -PT5H
timezone-from-dateTime(xs:dateTime("2000-06-12T13:20:00Z")) PT0S
timezone-from-dateTime(xs:dateTime("2004-08-27T00:00:00")) ()

W3C Documentation reference
fn:year-from-date()
Returns an xs:integer representing the year in the localized value of $arg. The value may be negative.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:date? $arg
Return type: xs:integer?

Examples:
Expression Result
year-from-date(xs:date("1999-05-31")) 1999
year-from-date(xs:date("2000-01-01+05:00")) 2000

W3C Documentation reference
fn:month-from-date()
Returns an xs:integer between 1 and 12, both inclusive, representing the month component in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:date? $arg
Return type: xs:integer?

Examples:
Expression Result
month-from-date(xs:date("1999-05-31-05:00")) 5
month-from-date(xs:date("2000-01-01+05:00")) 1

W3C Documentation reference
fn:day-from-date()
Returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:date? $arg
Return type: xs:integer?

Examples:
Expression Result
day-from-date(xs:date("1999-05-31-05:00")) 31
day-from-date(xs:date("2000-01-01+05:00")) 1

W3C Documentation reference
fn:timezone-from-date()
Returns the timezone component of $arg if any. If $arg has a timezone component, then the result is an xs:dayTimeDuration that indicates deviation from UTC; its value may range from +14:00 to -14:00 hours, both inclusive. Otherwise, the result is the empty sequence.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:date? $arg
Return type: xs:dayTimeDuration?

Examples:
Expression Result
timezone-from-date(xs:date("1999-05-31-05:00")) -PT5H
timezone-from-date(xs:date("2000-06-12Z")) PT0S

W3C Documentation reference
fn:hours-from-time()
Returns an xs:integer between 0 and 23, both inclusive, representing the value of the hours component in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:time? $arg
Return type: xs:integer?

Examples:
Expression Result
hours-from-time(xs:time("11:23:00")) 11
hours-from-time(xs:time("24:00:00")) 0

W3C Documentation reference
fn:minutes-from-time()
Returns an xs:integer between 0 and 23, both inclusive, representing the value of the hours component in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:time? $arg
Return type: xs:integer?

Examples:
Expression Result
hours-from-time(xs:time("11:23:00")) 11
hours-from-time(xs:time("24:00:00")) 0

W3C Documentation reference
fn:seconds-from-time()
Returns an xs:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:time? $arg
Return type: xs:decimal?

Examples:
Expression Result
seconds-from-time(xs:time("13:20:10.5")) 10.5

W3C Documentation reference
fn:timezone-from-time()
Returns an xs:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds in the localized value of $arg.
If $arg is the empty sequence, returns the empty sequence.

Arguments and return type:
Type Description
xs:time? $arg
Return type: xs:dayTimeDuration?

Examples:
Expression Result
timezone-from-time(xs:time("13:20:00-05:00")) -PT5H
timezone-from-time(xs:time("13:20:00")) ()

W3C Documentation reference
fn:adjust-date-to-timezone()
Adjusts an xs:date value to a specific timezone, or to no timezone at all. If $timezone is the empty sequence, returns an xs:date without a timezone. Otherwise, returns an xs:date with a timezone. For purposes of timezone adjustment, an xs:date is treated as an xs:dateTime with time 00:00:00.
If $timezone is not specified, then $timezone is the value of the implicit timezone in the dynamic context.
If $arg is the empty sequence, then the result is the empty sequence.
A dynamic error is raised [err:FODT0003] if $timezone is less than -PT14H or greater than PT14H or if does not contain an integral number of minutes.
If $arg does not have a timezone component and $timezone is the empty sequence, then the result is the value of $arg.
If $arg does not have a timezone component and $timezone is not the empty sequence, then the result is $arg with $timezone as the timezone component.
If $arg has a timezone component and $timezone is the empty sequence, then the result is the localized value of $arg without its timezone component.
If $arg has a timezone component and $timezone is not the empty sequence, then:
  • Let $srcdt be an xs:dateTime value, with 00:00:00 for the time component and date and timezone components that are the same as the date and timezone components of $arg.
  • Let $r be the result of evaluating fn:adjust-dateTime-to-timezone($srcdt, $timezone)
  • The result of this function will be a date value that has date and timezone components that are the same as the date and timezone components of $r.


Arguments and return type:
Type Description
xs:date? $arg
xs:dayTimeDuration? $timezone
Return type: xs:date?

Examples:
Expression Result
adjust-date-to-timezone(xs:date("2002-03-07")) 2002-03-07-05:00
adjust-date-to-timezone(xs:date("2002-03-07"), xs:dayTimeDuration("-PT10H")) 2002-03-07-10:00

W3C Documentation reference
fn:adjust-time-to-timezone()
Adjusts an xs:time value to a specific timezone, or to no timezone at all. If $timezone is the empty sequence, returns an xs:time without a timezone. Otherwise, returns an xs:time with a timezone.
If $timezone is not specified, then $timezone is the value of the implicit timezone in the dynamic context.
If $arg is the empty sequence, then the result is the empty sequence.
A dynamic error is raised [err:FODT0003] if $timezone is less than -PT14H or greater than PT14H or if does not contain an integral number of minutes.
If $arg does not have a timezone component and $timezone is the empty sequence, then the result is $arg.
If $arg does not have a timezone component and $timezone is not the empty sequence, then the result is $arg with $timezone as the timezone component.
If $arg has a timezone component and $timezone is the empty sequence, then the result is the localized value of $arg without its timezone component.
If $arg has a timezone component and $timezone is not the empty sequence, then:
  • Let $srcdt be an xs:dateTime value, with an arbitrary date for the date component and time and timezone components that are the same as the time and timezone components of $arg.
  • Let $r be the result of evaluating fn:adjust-dateTime-to-timezone($srcdt, $timezone)
  • The result of this function will be a time value that has time and timezone components that are the same as the time and timezone components of $r.


Arguments and return type:
Type Description
xs:time? $arg
xs:dayTimeDuration? $timezone
Return type: xs:time?

Examples:
Expression Result
adjust-time-to-timezone(xs:time("10:00:00")) 10:00:00-05:00
adjust-time-to-timezone(xs:time("10:00:00"), xs:dayTimeDuration("-PT10H")) 10:00:00-10:00

W3C Documentation reference
fn:current-dateTime()
Returns the current dateTime (with timezone) from the dynamic context. (See Section C.2 Dynamic Context ComponentsXP.) This is an xs:dateTime that is current at some time during the evaluation of a query or transformation in which fn:current-dateTime() is executed. This function is ·stable·. The precise instant during the query or transformation represented by the value of fn:current-dateTime() is ·implementation dependent·.

Return type: xs:dateTime

Examples:
Expression Result
current-dateTime() xs:dateTime corresponding to the current date and time

W3C Documentation reference
fn:current-date()
Returns xs:date(fn:current-dateTime()). This is an xs:date (with timezone) that is current at some time during the evaluation of a query or transformation in which fn:current-date() is executed. This function is ·stable·. The precise instant during the query or transformation represented by the value of fn:current-date() is ·implementation dependent·.

Return type: xs:date

Examples:
Expression Result
current-date() xs:date corresponding to the current date

W3C Documentation reference
fn:current-time()
Returns xs:date(fn:current-dateTime()). This is an xs:date (with timezone) that is current at some time during the evaluation of a query or transformation in which fn:current-date() is executed. This function is ·stable·. The precise instant during the query or transformation represented by the value of fn:current-date() is ·implementation dependent·.

Return type: xs:time

Examples:
Expression Result
current-time() xs:date corresponding to the current time

W3C Documentation reference
fn:implicit-timezone()
Returns the value of the implicit timezone property from the dynamic context. Components of the dynamic context are discussed in Section C.2 Dynamic Context ComponentsXP.

Return type: xs:string

Examples:
Expression Result
implicit-timezone() PT0S

W3C Documentation reference
fn:error()
The fn:error function is a general function that may be invoked as above but may also be invoked from [XQuery 1.0: An XML Query Language] or [XML Path Language (XPath) 2.0] applications with, for example, an xs:QName argument.
W3C Documentation reference
fn:trace()
Provides an execution trace intended to be used in debugging queries.
The input $value is returned, unchanged, as the result of the function. In addition, the inputs $value, converted to an xs:string, and $label may be directed to a trace data set. The destination of the trace output is ·implementation-defined·. The format of the trace output is ·implementation dependent·. The ordering of output from invocations of the fn:trace() function is ·implementation dependent·.
Arguments:
Type Description
item* $value
xs:string $label
Return type: item


W3C Documentation reference
fn:resolve-uri()
This function enables a relative URI reference to be resolved against an absolute URI. The first form of this function resolves $relative against the value of the base-uri property from the static context. If the base-uri property is not initialized in the static context an error is raised [err:FONS0005].
If $relative is a relative URI reference, it is resolved against $base, or against the base-uri property from the static context, using an algorithm such as those described in [RFC 2396] or [RFC 3986], and the resulting absolute URI reference is returned.
If $relative is an absolute URI reference, it is returned unchanged.
If $relative is the empty sequence, the empty sequence is returned.
If $relative is not a valid URI according to the rules of the xs:anyURI data type, or if it is not a suitable relative reference to use as input to the chosen resolution algorithm, then an error is raised [err:FORG0002].
If $base is not a valid URI according to the rules of the xs:anyURI data type, if it is not a suitable URI to use as input to the chosen resolution algorithm (for example, if it is a relative URI reference, if it is a non-hierarchic URI, or if it contains a fragment identifier), then an error is raised [err:FORG0002].
If the chosen resolution algorithm fails for any other reason then an error is raised [err:FORG0009].

Note:

Resolving a URI does not dereference it. This is merely a syntactic operation on two character strings.

Arguments and return type:
Type Description
xs:string? $relative
xs:string $base
Return type: xs:anyURI?


W3C Documentation reference
fn:resolve-QName()
Returns an xs:QName value (that is, an expanded-QName) by taking an xs:string that has the lexical form of an xs:QName (a string in the form "prefix:local-name" or "local-name") and resolving it using the in-scope namespaces for a given element.
If $qname does not have the correct lexical form for xs:QName an error is raised [err:FOCA0002].
If $qname is the empty sequence, returns the empty sequence.
More specifically, the function searches the namespace bindings of $element for a binding whose name matches the prefix of $qname, or the zero-length string if it has no prefix, and constructs an expanded-QName whose local name is taken from the supplied $qname, and whose namespace URI is taken from the string value of the namespace binding.
If the $qname has a prefix and if there is no namespace binding for $element that matches this prefix, then an error is raised [err:FONS0004].
If the $qname has no prefix, and there is no namespace binding for $element corresponding to the default (unnamed) namespace, then the resulting expanded-QName has no namespace part.
The prefix (or absence of a prefix) in the supplied $qname argument is retained in the returned expanded-QName, as discussed in Section 2.1 TerminologyDM.

Arguments:
Type Description
xs:string? $qname
element $element
Return type: xs:QName?

Examples:
Query Result
resolve-QName("hello", /l:library/l:libraryName) hello
resolve-QName("l:libraryID", /l:library/l:libraryName) l:libraryID

W3C Documentation reference
fn:QName()
Returns an xs:QName with the namespace URI given in $paramURI. If $paramURI is the zero-length string or the empty sequence, it represents "no namespace"; in this case, if the value of $paramQName contains a colon (:), an error is raised [err:FOCA0002]. The prefix (or absence of a prefix) in $paramQName is retained in the returned xs:QName value. The local name in the result is taken from the local part of $paramQName.
If $paramQName does not have the correct lexical form for xs:QName an error is raised [err:FOCA0002].
Note that unlike xs:QName this function does not require a xs:string literal as the argument.

Arguments:
Type Description
xs:string? $paramURI
xs:string $paramQName
Return type: xs:QName

Examples:
Query Result
QName("http://www.release11.com/library", "l:libraryName") l:libraryName
For more extensive examples see W3C documentation below.
W3C Documentation reference
fn:prefix-from-QName()
Returns an xs:NCName representing the prefix of $arg. The empty sequence is returned if $arg is the empty sequence or if the value of $arg contains no prefix.

Arguments:
Type Description
xs:QName? $arg
Return type: xs:NCName?

Examples:
Query Result
prefix-from-QName(resolve-QName("l:library", /l:library)) l
W3C Documentation reference
fn:local-name-from-QName()
Returns an xs:NCName representing the local part of $arg. If $arg is the empty sequence, returns the empty sequence.

Arguments:
Type Description
xs:QName? $arg
Return type: xs:NCName?

Examples:
Query Result
prefix-from-QName(resolve-QName("l:library", /l:library)) library
W3C Documentation reference
fn:prefix-from-QName()
Returns an xs:NCName representing the prefix of $arg. The empty sequence is returned if $arg is the empty sequence or if the value of $arg contains no prefix.

Arguments:
Type Description
xs:QName? $arg
Return type: xs:NCName?

Examples:
Query Result
prefix-from-QName(resolve-QName("l:library", /l:library)) l
W3C Documentation reference
fn:namespace-uri-from-QName()
Returns the namespace URI for $arg as an xs:anyURI. If $arg is the empty sequence, the empty sequence is returned. If $arg is in no namespace, the zero-length xs:anyURI is returned.

Arguments:
Type Description
xs:QName? $arg
Return type: xs:anyURI?

Examples:
Query Result
prefix-from-QName(resolve-QName("l:library", /l:library)) http://www.release11.com/library
W3C Documentation reference
fn:namespace-uri-for-prefix()
Returns the namespace URI of one of the in-scope namespaces for $element, identified by its namespace prefix.
If $element has an in-scope namespace whose namespace prefix is equal to $prefix, it returns the namespace URI of that namespace. If $prefix is the zero-length string or the empty sequence, it returns the namespace URI of the default (unnamed) namespace. Otherwise, it returns the empty sequence.
Prefixes are equal only if their Unicode code points match exactly.

Arguments:
Type Description
xs:string? $prefix
element() $element
Return type: xs:anyURI?

Examples:
Query Result
namespace-uri-for-prefix("l", /l:library) http://www.release11.com/library
W3C Documentation reference
fn:in-scope-prefixes()
Returns the prefixes of the in-scope namespaces for $element. For namespaces that have a prefix, it returns the prefix as an xs:NCName. For the default namespace, which has no prefix, it returns the zero-length string.

Arguments:
Type Description
element() $element
Return type: xs:string*

Examples:
Query Result
in-scope-prefixes(/l:library) b
l
p
xsi
xml
W3C Documentation reference
fn:static-base-uri()
Returns the value of the Base URI property from the static context. If the Base URI property is undefined, the empty sequence is returned. Components of the static context are discussed in Section C.1 Static Context ComponentsXP.

Return type: xs:anyURI?

Examples:
Expression Result
static-base-uri()() <empty sequence>

W3C Documentation reference
fn:outermost(node()*)
Returns the outermost nodes of the input sequence that are not ancestors of any other node in the input sequence
Arguments and return type:
Type Description
node()* Sequence of nodes
Examples:
Expression Result
fn:outermost(//chapter) Sequence of outermost chapter nodes
fn:outermost(/book//*) Sequence of outermost nodes in the book

W3C Documentation reference: outermost
fn:innermost(node()*)
Returns the innermost nodes of the input sequence that are not descendants of any other node in the input sequence
Arguments and return type:
Type Description
node()* Sequence of nodes
Examples:
Expression Result
fn:innermost(//chapter) Sequence of innermost chapter nodes
fn:innermost(/book//*) Sequence of innermost nodes in the book

W3C Documentation reference: innermost
fn:has-children(node()?)
Returns true if the specified node has one or more children, otherwise returns false
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:has-children(/book/chapter[1]) true
fn:has-children(/book/chapter[1]/title) false

W3C Documentation reference: has-children
fn:path(node()?)
Returns a string that represents the path of the specified node within the XML document
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:path(/book/chapter[1]) /book/chapter[1]
fn:path(/book/chapter[2]/title) /book/chapter[2]/title

W3C Documentation reference: path
fn:root(node()?)
Returns the root node of the tree that contains the specified node
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:root(/book/chapter) <book> element (root node)
fn:root(/book/chapter[1]) <book> element (root node)

W3C Documentation reference: root
fn:namespace-uri(node()?)
Returns the namespace URI of the specified node
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:namespace-uri(/example:root) "http://www.example.com/ns"
fn:namespace-uri(/a/b) ""

W3C Documentation reference: namespace-uri
fn:local-name(node()?)
Returns the local part of the name of the specified node
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:local-name(/a/b) "b"
fn:local-name(/example:root) "root"

W3C Documentation reference: local-name
fn:name(node()?)
Returns the expanded QName of the specified node as a string
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:name(/a/b) "b"
fn:name(/example:root) "example:root"

W3C Documentation reference: name
fn:document-uri(node?)
Returns the document URI of the given node or the context item
Arguments and return type:
Type Description
node? Returns the document URI of the specified node or the context item (if no argument is provided)
Examples:
Expression Result
fn:document-uri(/library/fiction:book[1]) http://example.com/library.xml (assuming the document URI of the first fiction:book element is "http://example.com/library.xml")
fn:document-uri(/library) http://example.com/library.xml (assuming the document URI of the library element is "http://example.com/library.xml")

W3C Documentation reference: Document-URI
fn:base-uri(node?)
Returns the base URI of the node or the context item
Arguments and return type:
Type Description
node? Returns the base URI of the specified node or the context item (if no argument is provided)
Examples:
Expression Result
fn:base-uri(/library/fiction:book[1]) http://example.com/library.xml (assuming the base URI of the first fiction:book element is "http://example.com/library.xml")
fn:base-uri(/library) http://example.com/library.xml (assuming the base URI of the library element is "http://example.com/library.xml")

W3C Documentation reference: Base-URI
fn:node-name(node?)
Returns the name of a node as an xs:QName
Arguments and return type:
Type Description
node? Returns the name of the specified node or the context item if the argument is omitted
Examples:
Expression Result
fn:node-name(/library/*[1]) fiction:book
fn:node-name(/library/fiction:book[1]/title) title

W3C Documentation reference: Node-Name
fn:not(item()*)
Returns the negation of the effective boolean value of the argument
Arguments and return type:
Type Description
item()* Argument whose effective boolean value is to be negated
Examples:
Expression Result
fn:not(1) false
fn:not(0) true
fn:not('') true
fn:not('true') false

W3C Documentation reference: Not
fn:false()
Returns the boolean value false
Arguments and return type:
Type Description
None Returns the boolean value false
Examples:
Expression Result
fn:false() false
//item[fn:false()] Returns an empty node-set

W3C Documentation reference: False
fn:true()
Returns the boolean value true
Arguments and return type:
Type Description
None Returns the boolean value true
Examples:
Expression Result
fn:true() true
//item[fn:true()] Returns all <item> elements

W3C Documentation reference: True
fn:boolean(item()*)
Converts the argument to a boolean value
Arguments and return type:
Type Description
item()* Argument to be converted to a boolean value
Examples:
Expression Result
fn:boolean(1) true
fn:boolean(0) false
fn:boolean('') false
fn:boolean('true') true

W3C Documentation reference: Boolean
fn:unparsed-text-available(xs:string?, xs:string?)
Determines if an unparsed text resource identified by a URI can be read using the given encoding
Arguments and return type:
Type Description
xs:string? The URI identifying the unparsed text resource
xs:string? The encoding to be used for reading the resource
xs:boolean Indicates if the resource can be read using the given encoding
Examples:
Expression Result
fn:unparsed-text-available("http://www.example.com/text.txt", "UTF-8") Returns true if the text resource identified by the specified URI can be read using the specified encoding, otherwise false

W3C Documentation reference: unparsed-text-available
fn:unparsed-text-lines(xs:string?, xs:string?)
Returns the contents of an unparsed text resource identified by a URI, split into lines
Arguments and return type:
Type Description
xs:string? The URI identifying the unparsed text resource
xs:string? The encoding to be used for reading the resource
xs:string* The lines of the unparsed text resource
Examples:
Expression Result
fn:unparsed-text-lines("http://www.example.com/text.txt", "UTF-8") Returns the lines of the text resource identified by the specified URI, using the specified encoding

W3C Documentation reference: unparsed-text-lines
fn:unparsed-text(xs:string?, xs:string?)
Returns the contents of an unparsed text resource identified by a URI
Arguments and return type:
Type Description
xs:string? The URI identifying the unparsed text resource
xs:string? The encoding to be used for reading the resource
xs:string? The contents of the unparsed text resource
Examples:
Expression Result
fn:unparsed-text("http://www.example.com/text.txt", "UTF-8") Returns the contents of the text resource identified by the specified URI, using the specified encoding

W3C Documentation reference: unparsed-text
fn:escape-html-uri(xs:string?)
Escapes special characters in a URI to be used in HTML
Arguments and return type:
Type Description
xs:string? URI to be escaped for use in HTML
Examples:
Expression Result
fn:escape-html-uri('https://example.com/search?q=test&lang=en') https://example.com/search?q=test&lang=en
fn:escape-html-uri('https://example.com/page?id=1§ion=2') https://example.com/page?id=1&section=2

W3C Documentation reference: Escape-HTML-URI
fn:iri-to-uri(xs:string?)
Converts an IRI to a URI by escaping non-ASCII characters
Arguments and return type:
Type Description
xs:string? IRI to be converted to a URI
Examples:
Expression Result
fn:iri-to-uri('https://example.com/ümlaut') https://example.com/%C3%BCmlaut
fn:iri-to-uri('https://example.com/日本語') https://example.com/%E6%97%A5%E6%9C%AC%E8%AA%9E

W3C Documentation reference: IRI-to-URI
fn:encode-for-uri(xs:string?)
Encodes a string for use in a URI by escaping special characters
Arguments and return type:
Type Description
xs:string? String to be encoded for use in a URI
Examples:
Expression Result
fn:encode-for-uri('hello world') hello%20world
fn:encode-for-uri('example?query=value¶m=value2') example%3Fquery%3Dvalue%26param%3Dvalue2

W3C Documentation reference: Encode-for-URI
fn:resolve-uri(xs:string?, xs:string?)
Resolves a relative URI using a base URI
Arguments and return type:
Type Description
xs:string? Relative URI to resolve
xs:string? Base URI to use for resolving (optional)
Examples:
Expression Result
fn:resolve-uri('example.html', 'https://www.example.com/folder/') https://www.example.com/folder/example.html
fn:resolve-uri('../images/pic.jpg', 'https://www.example.com/folder/page.html') https://www.example.com/images/pic.jpg

W3C Documentation reference: Resolve-URI
fn:analyze-string(xs:string?, xs:string, xs:string?)
Analyzes the input string and returns an XML fragment containing match and non-match elements
Arguments and return type:
Type Description
xs:string? Input string to analyze
xs:string Regular expression pattern to match
xs:string? Flags to control the regular expression matching (optional)
Examples:
Expression Result
fn:analyze-string('red,green,blue', ',') <fn:analyze-string-result><fn:non-match>red</fn:non-match><fn:match>, <fn:non-match>green</fn:non-match><fn:match>, <fn:non-match>blue</fn:non-match></fn:analyze-string-result>

W3C Documentation reference: Analyze-String
fn:tokenize(xs:string?, xs:string, xs:string?)
Splits the input string into a sequence of substrings using the pattern as a delimiter
Arguments and return type:
Type Description
xs:string? Input string to tokenize
xs:string Regular expression pattern to use as delimiter
xs:string? Flags to control the regular expression matching (optional)
Examples:
Expression Result
fn:tokenize('XPath 3.0, XQuery 3.0, XSLT 3.0', ',\\s*') ('XPath 3.0', 'XQuery 3.0', 'XSLT 3.0')
fn:tokenize('apple,orange,banana', ',') ('apple', 'orange', 'banana')

W3C Documentation reference: Tokenize
fn:replace(xs:string?, xs:string, xs:string, xs:string?)
Replaces occurrences of the pattern in the input string with the replacement string
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string Regular expression pattern to match
xs:string Replacement string
xs:string? Flags to control the regular expression matching (optional)
Examples:
Expression Result
fn:replace('XPath 3.0 is great', '3.0', '3.1') 'XPath 3.1 is great'
fn:replace('Hello, World!', 'World', 'XPath') 'Hello, XPath!'

W3C Documentation reference: Replace
fn:matches(xs:string?, xs:string, xs:string?)
Returns true if the input string matches the regular expression pattern, otherwise false
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string Regular expression pattern to match
xs:string? Flags to control the regular expression matching (optional)
Examples:
Expression Result
fn:matches('XPath 3.0', '\\d\\.\\d') true
fn:matches('Hello, World!', '[A-Z][a-z]*') true
fn:matches('example123', '\\d+', 'q') false

W3C Documentation reference: Matches
fn:substring-after(xs:string?, xs:string?)
Returns the part of the first string that follows the first occurrence of the second string
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string? Substring to search for
Examples:
Expression Result
fn:substring-after('Hello, World!', ',') ' World!'
fn:substring-after('XPath 3.0 is awesome!', '3.0') ' is awesome!'

W3C Documentation reference: Substring-After
fn:substring-before(xs:string?, xs:string?)
Returns the part of the first string that precedes the first occurrence of the second string
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string? Substring to search for
Examples:
Expression Result
fn:substring-before('Hello, World!', ',') 'Hello'
fn:substring-before('XPath 3.0 is awesome!', '3.0') 'XPath '

W3C Documentation reference: Substring-Before
fn:ends-with(xs:string?, xs:string?)
Returns true if the first string ends with the second string, otherwise false
Arguments and return type:
Type Description
xs:string? Input string to check
xs:string? Substring to check for at the end of the first string
Examples:
Expression Result
fn:ends-with('Hello, World!', 'World!') true
fn:ends-with('Hello, World!', 'Hello') false
fn:ends-with('XPath 3.0', '3.0') true

W3C Documentation reference: Ends-With
fn:starts-with(xs:string?, xs:string?)
Returns true if the first string starts with the second string, otherwise false
Arguments and return type:
Type Description
xs:string? Input string to check
xs:string? Substring to check for at the beginning of the first string
Examples:
Expression Result
fn:starts-with('Hello, World!', 'Hello') true
fn:starts-with('Hello, World!', 'World') false
fn:starts-with('XPath 3.0', 'XPath') true

W3C Documentation reference: Starts-With
fn:contains(xs:string?, xs:string?)
Returns true if the first string contains the second string, otherwise false
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string? Substring to search for
Examples:
Expression Result
fn:contains('Hello, World!', 'World') true
fn:contains('Hello, World!', 'world') false
fn:contains('XPath 3.0', '3.0') true

W3C Documentation reference: Contains
fn:translate(xs:string?, xs:string, xs:string)
Returns the input string with specified characters replaced
Arguments and return type:
Type Description
xs:string? Input string to be translated
xs:string Map string with characters to replace
xs:string Translate string with replacement characters
Examples:
Expression Result
fn:translate('apple', 'aeiou', '12345') '1ppl2'
fn:translate('Hello, World!', 'HW', 'hw') 'hello, world!'

W3C Documentation reference: Translate
fn:lower-case(xs:string?)
Returns the input string with all characters converted to lowercase
Arguments and return type:
Type Description
xs:string? Input string to convert to lowercase
Examples:
Expression Result
fn:lower-case('HELLO, WORLD!') 'hello, world!'
fn:lower-case('XPath 3.0') 'xpath 3.0'
fn:lower-case('BANANA') 'banana'

W3C Documentation reference: Lower-Case
fn:upper-case(xs:string?)
Returns the input string with all characters converted to uppercase
Arguments and return type:
Type Description
xs:string? Input string to convert to uppercase
Examples:
Expression Result
fn:upper-case('Hello, World!') 'HELLO, WORLD!'
fn:upper-case('XPath 3.0') 'XPATH 3.0'
fn:upper-case('banana') 'BANANA'

W3C Documentation reference: Upper-Case
fn:normalize-unicode(xs:string?, xs:string)
Returns the input string with Unicode normalization applied
Arguments and return type:
Type Description
xs:string? Input string to normalize
xs:string Normalization form to apply (NFC, NFD, NFKC, NFKD)
Examples:
Expression Result
fn:normalize-unicode('Café', 'NFC') 'Café'
fn:normalize-unicode('Café', 'NFD') 'Café'

W3C Documentation reference: Normalize-Unicode
fn:normalize-space(xs:string?)
Returns the input string with whitespace normalized
Arguments and return type:
Type Description
xs:string? Input string to normalize whitespace
Examples:
Expression Result
fn:normalize-space(' Hello, World! ') 'Hello, World!'
fn:normalize-space(' XPath 3.0 ') 'XPath 3.0'
fn:normalize-space('\tbanana\t') 'banana'

W3C Documentation reference: Normalize-Space
fn:string-length(xs:string?)
Returns the length of the input string
Arguments and return type:
Type Description
xs:string? Input string to calculate length
Examples:
Expression Result
fn:string-length('Hello, World!') 13
fn:string-length('XPath 3.0') 8
fn:string-length('banana') 6

W3C Documentation reference: String-Length
fn:substring(xs:string?, xs:double)
Returns a substring of the source string, starting from a specific location
Arguments and return type:
Type Description
xs:string? Input source string
xs:double Starting location to extract the substring
Examples:
Expression Result
fn:substring('Hello, World!', 1, 5) 'Hello'
fn:substring('XPath 3.0', 7) '3.0'
fn:substring('banana', 2, 3) 'ana'

W3C Documentation reference: Substring
fn:string-join(xs:string*, xs:string)
Joins a sequence of strings with a specified separator, returning a single string
Arguments and return type:
Type Description
xs:string* Input sequence of strings to join
xs:string Separator string to insert between joined strings
Examples:
Expression Result
fn:string-join(('apple', 'banana', 'orange'), ', ') 'apple, banana, orange'
fn:string-join(('XPath', '3.0', 'Functions'), ' - ') 'XPath - 3.0 - Functions'
fn:string-join(('A', 'B', 'C'), '') 'ABC'

W3C Documentation reference: String-Join
fn:concat(xs:anyAtomicType?, xs:anyAtomicType?, ...)
Concatenates two or more strings or atomic values, returning a single string
Arguments and return type:
Type Description
xs:anyAtomicType? Input strings or atomic values to concatenate
Examples:
Expression Result
fn:concat('Hello', ' ', 'World') 'Hello World'
fn:concat('I have ', 3, ' apples') 'I have 3 apples'
fn:concat('XPath ', '3.0') 'XPath 3.0'

W3C Documentation reference: Concat
fn:codepoint-equal(xs:string?, xs:string?)
Compares two strings on a codepoint-by-codepoint basis and returns true if they are equal, false otherwise
Arguments and return type:
Type Description
xs:string? First string to compare
xs:string? Second string to compare
Examples:
Expression Result
fn:codepoint-equal('Hello', 'Hello') true
fn:codepoint-equal('Hello', 'hello') false
fn:codepoint-equal('apple', 'banana') false

W3C Documentation reference: Codepoint-Equal
fn:compare(xs:string?, xs:string?)
Compares two strings and returns -1, 0, or 1 if the first string is less than, equal to, or greater than the second string, respectively
Arguments and return type:
Type Description
xs:string? First string to compare
xs:string? Second string to compare
Examples:
Expression Result
fn:compare('apple', 'banana') -1
fn:compare('apple', 'apple') 0
fn:compare('banana', 'apple') 1

W3C Documentation reference: Compare
fn:string-to-codepoints(xs:string?)
Returns a sequence of Unicode code points for a given string
Arguments and return type:
Type Description
xs:string? Input string
Examples:
Expression Result
fn:string-to-codepoints('Hello') (72, 101, 108, 108, 111)
fn:string-to-codepoints('( ͡° ͜ʖ ͡°)') (40, 32, 865, 176, 32, 860, 662, 32, 865, 176, 41)
fn:string-to-codepoints('😊') (128522)

W3C Documentation reference: String-To-Codepoints
fn:codepoints-to-string(xs:integer*)
Constructs a string from a sequence of Unicode code points
Arguments and return type:
Type Description
xs:integer* Sequence of Unicode code points
Examples:
Expression Result
fn:codepoints-to-string((72, 101, 108, 108, 111)) Hello
codepoints-to-string((40, 32, 865, 176, 32, 860, 662, 32, 865, 176, 41)) ( ͡° ͜ʖ ͡°)
fn:codepoints-to-string((128522)) 😊

W3C Documentation reference: Codepoints-To-String
fn:string(object)
Returns the string representation of the object argument
Arguments and return type:
Type Description
string The object to convert to a string
Examples:
Expression Result
string((1<0)) false
string(.11) 0.11

W3C Documentation reference: String-Functions
fn:format-number(numeric?, xs:string, $decimal-format-name)
Formats a numeric value according to the supplied picture string and optional decimal format name
Arguments and return type:
Type Description
numeric? Numeric value to be formatted
xs:string Picture string defining the format
xs:string? Optional decimal format name
Examples:
Expression Result
fn:format-number(1234.567, '0.00') 1,234.57
fn:format-number(-1234.567, '0.00') -1,234.57
fn:format-number(0.12345, '0.00%') 12.35%

W3C Documentation reference: Format-Number
fn:format-integer(xs:integer?, xs:string)
Formats an integer value according to the supplied picture string
Arguments and return type:
Type Description
xs:integer? Integer value to be formatted
xs:string Picture string defining the format
Examples:
Expression Result
fn:format-integer(12345, '0,0') 12,345
fn:format-integer(-1234, '0,0') -1,234
fn:format-integer(1234, '00-00-00') 01-23-45

W3C Documentation reference: Format-Integer
fn:round-half-to-even(numeric?)
Returns the closest integer to the given numeric value, rounding half-way cases to the nearest even integer (also known as "bankers' rounding")
Arguments and return type:
Type Description
numeric? Numeric value for which the rounded value will be calculated
Examples:
Expression Result
fn:round-half-to-even(3.5) 4
fn:round-half-to-even(2.5) 2
fn:round-half-to-even(-1.5) -2
fn:round-half-to-even(xs:decimal('1.25'), 1) 1.2

W3C Documentation reference: Round-Half-To-Even
fn:round(numeric?)
Returns the closest integer to the given numeric value, rounding half-way cases away from zero
Arguments and return type:
Type Description
numeric? Numeric value for which the rounded value will be calculated
Examples:
Expression Result
fn:round(3.14) 3
fn:round(-4.7) -5
fn:round(xs:decimal('2.5')) 3

W3C Documentation reference: Round
fn:floor(numeric?)
Returns the largest integer less than or equal to the given numeric value
Arguments and return type:
Type Description
numeric? Numeric value for which the floor value will be calculated
Examples:
Expression Result
fn:floor(3.14) 3
fn:floor(-4.7) -5
fn:floor(xs:decimal('2.5')) 2

W3C Documentation reference: Floor
fn:ceiling(numeric?)
Returns the smallest integer greater than or equal to the given numeric value
Arguments and return type:
Type Description
numeric? Numeric value for which the ceiling value will be calculated
Examples:
Expression Result
fn:ceiling(3.14) 4
fn:ceiling(-4.7) -4
fn:ceiling(xs:decimal('2.5')) 3

W3C Documentation reference: Ceiling
fn:abs(numeric?)
Returns the absolute value of the given numeric value
Arguments and return type:
Type Description
numeric? Numeric value for which the absolute value will be calculated
Examples:
Expression Result
fn:abs(-42) 42
fn:abs(3.14) 3.14
fn:abs(xs:decimal('-5.5')) 5.5

W3C Documentation reference: Abs
fn:number(item?)
Converts the given value to a number
Arguments and return type:
Type Description
item? Returns the numeric value of the specified expression or the context item (if no argument is provided)
Examples:
Expression Result
fn:number(/library/fiction:book[1]/@id) 1 (if the first fiction:book element's id attribute is "1")
fn:number(/library/fiction:book[1]/price) 19.99 (if the first fiction:book element's price element contains "19.99")

W3C Documentation reference: Number
fn:fold-right(item()*, item()*, function(item(), item()*))
Applies a processing function cumulatively to the items of a sequence from right to left, so as to reduce the sequence to a single value
Arguments and return type:
Type Description
item()* The input sequence of items
item()* The initial value, also known as the zero value
function(item(), item()*) The processing function used to accumulate the items
item()* The resulting single value after applying the processing function
Examples:
Expression Result
fold-right((1, 2, 3, 4), 0, function($current, $accumulator) { $accumulator - $current }) Returns the result of subtracting each number in the input sequence from right to left: -2

W3C Documentation reference: fold-right
fn:fold-left(item()*, item()*, function(item()*, item()))
Applies a processing function cumulatively to the items of a sequence from left to right, so as to reduce the sequence to a single value
Arguments and return type:
Type Description
item()* The input sequence of items
item()* The initial value, also known as the zero value
function(item()*, item()) The processing function used to accumulate the items
item()* The resulting single value after applying the processing function
Examples:
Expression Result
fold-left((1, 2, 3, 4), 0, function($accumulator, $current) { $accumulator + $current }) Returns the sum of the numbers in the input sequence: 10

W3C Documentation reference: fold-left
fn:last()
Returns the position of the last item in the current context sequence
Arguments and return type:
Type Description
None Returns the position of the last item in the current context sequence
Examples:
Expression Result
/library/fiction:book[position() = last()] Returns the last fiction:book element in the library
/library/fiction:book[last()] Returns the last fiction:book element in the library

W3C Documentation reference: Last
fn:position()
Returns the context position of the context item in the sequence currently being processed
Arguments and return type:
Type Description
None Function takes no arguments
xs:integer The position of the context item in the sequence
Examples:
Expression Result
<items><item>Item 1</item><item>Item 2</item></items>/item[position()=2] Returns '<item>Item 2</item>'
<items><item>Item 1</item><item>Item 2</item></items>/item[position()=1] Returns '<item>Item 1</item>'

W3C Documentation reference: position
fn:collection(xs:string?)
Returns a sequence of documents in a collection identified by a URI
Arguments and return type:
Type Description
xs:string? The URI identifying the collection of documents
xs:anyAtomicType* A sequence of documents in the collection
Examples:
Expression Result
fn:collection("http://www.example.com/collection/") Returns a sequence of documents in the collection identified by the specified URI
fn:collection() Returns a sequence of documents in the default collection, if one is defined

W3C Documentation reference: collection
fn:sum(xs:anyAtomicType*, xs:anyAtomicType?)
Returns the sum of a sequence of numeric values
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of numeric values
xs:anyAtomicType? Value to return if the sequence is empty (optional)
xs:anyAtomicType? Sum of the input sequence
Examples:
Expression Result
fn:sum((10, 20, 30, 40, 50)) 150
fn:sum((), 0) 0

W3C Documentation reference: sum
fn:min(xs:anyAtomicType*, xs:string)
Returns the minimum value from a sequence of values
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of values
xs:string Collation to use when comparing strings
xs:anyAtomicType? Minimum value in the input sequence
Examples:
Expression Result
fn:min((10, 20, 30, 40, 50)) 10
fn:min(("apple", "banana", "cherry"), "http://www.w3.org/2005/xpath-functions/collation/codepoint") "apple"
fn:min(()) empty sequence

W3C Documentation reference: min
fn:max(xs:anyAtomicType*, xs:string)
Returns the maximum value from a sequence of values
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of values
xs:string Collation to use when comparing strings
xs:anyAtomicType? Maximum value in the input sequence
Examples:
Expression Result
fn:max((10, 20, 30, 40, 50)) 50
fn:max(("apple", "banana", "cherry"), "http://www.w3.org/2005/xpath-functions/collation/codepoint") "cherry"
fn:max(()) empty sequence

W3C Documentation reference: max
fn:avg(xs:anyAtomicType*)
Computes the average of the numeric values in the input sequence
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of numeric values
xs:anyAtomicType? Average of the numeric values in the input sequence
Examples:
Expression Result
fn:avg((10, 20, 30, 40, 50)) 30
fn:avg((2.5, 3.5, 4.5)) 3.5
fn:avg(()) empty sequence

W3C Documentation reference: avg
fn:count(item()*)
Returns the number of items in the input sequence
Arguments and return type:
Type Description
item()* Input sequence
xs:integer Number of items in the input sequence
Examples:
Expression Result
fn:count(('apple', 'banana', 'orange')) 3
fn:count(()) 0
fn:count((1, 2, 3, 4, 5)) 5

W3C Documentation reference: count
fn:exactly-one(item()*)
Returns the single item in the input sequence or raises an error if the sequence is empty or contains more than one item
Arguments and return type:
Type Description
item()* Input sequence
item() Single item from the input sequence, otherwise an error is raised
Examples:
Expression Result
fn:exactly-one(('apple')) 'apple'
fn:exactly-one(('apple', 'banana')) Error (more than one item)
fn:exactly-one(()) Error (empty sequence)

W3C Documentation reference: exactly-one
fn:one-or-more(item()*)+
Returns the input sequence if it contains one or more items, otherwise raises an error
Arguments and return type:
Type Description
item()* Input sequence
item()+ Sequence containing one or more items, otherwise an error is raised
Examples:
Expression Result
fn:one-or-more(('apple', 'banana')) ('apple', 'banana')
fn:one-or-more(('pear')) ('pear')

W3C Documentation reference: one-or-more
fn:zero-or-one(item()*)
Returns the input sequence if it contains zero or one items, otherwise raises an error
Arguments and return type:
Type Description
item()* Input sequence
item()? Sequence containing zero or one item, otherwise an error is raised
Examples:
Expression Result
fn:zero-or-one(('apple')) ('apple')
fn:zero-or-one(()) ()

W3C Documentation reference: zero-or-one
fn:deep-equal(item()* , item()*)
Returns true if the two input sequences are deep-equal, meaning that they have the same structure and atomic values
Arguments and return type:
Type Description
item()* First input sequence
item()* Second input sequence
xs:boolean True if the input sequences are deep-equal, otherwise false
Examples:
Expression Result
fn:deep-equal((1, 2, 3), (1, 2, 3)) true
fn:deep-equal((1, 2, 3), (1, 2, 4)) false

W3C Documentation reference: deep-equal
fn:index-of(xs:anyAtomicType*, xs:anyAtomicType)
Returns a sequence of integers indicating the positions of items in the input sequence that are equal to the search item
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of atomic values
xs:anyAtomicType Search item to find in the input sequence
xs:integer* Sequence of integers representing the positions of the search item in the input sequence
Examples:
Expression Result
fn:index-of((3, 1, 4, 1, 5, 9, 2, 2, 3), 1) (2, 4)
fn:index-of(('apple', 'banana', 'orange', 'apple', 'grape', 'orange'), 'apple') (1, 4)

W3C Documentation reference: index-of
fn:distinct-values(xs:anyAtomicType*)
Returns a sequence of distinct atomic values from the input sequence
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of atomic values
xs:anyAtomicType* Distinct sequence of atomic values
Examples:
Expression Result
fn:distinct-values((3, 1, 4, 1, 5, 9, 2, 2, 3)) (3, 1, 4, 5, 9, 2)
fn:distinct-values(('apple', 'banana', 'orange', 'apple', 'grape', 'orange')) ('apple', 'banana', 'orange', 'grape')

W3C Documentation reference: distinct-values
fn:unordered(item()*)
Returns the items of a sequence in an implementation-dependent order
Arguments and return type:
Type Description
item()* Input sequence
item()* Unordered sequence
Examples:
Expression Result
fn:unordered((3, 1, 4, 1, 5, 9, 2)) (1, 2, 3, 4, 5, 9, 1) (example result; actual order may vary)
fn:unordered(('apple', 'banana', 'orange', 'grape')) ('banana', 'apple', 'orange', 'grape') (example result; actual order may vary)

W3C Documentation reference: unordered
fn:subsequence(item()*, xs:double, xs:double)
Returns a subsequence of a given sequence starting at a specified position with a specified length
Arguments and return type:
Type Description
item()* Input sequence
xs:double Starting position
xs:double Length of subsequence
item()* Subsequence
Examples:
Expression Result
fn:subsequence((1, 2, 3, 4, 5), 2, 3) (2, 3, 4)
fn:subsequence(('apple', 'banana', 'orange', 'grape'), 1, 2) ('apple', 'banana')
fn:subsequence(('red', 'blue', 'green', 'yellow'), 3) ('green', 'yellow')

W3C Documentation reference: subsequence
fn:reverse(item()*)
Reverses the order of items in a sequence
Arguments and return type:
Type Description
item()* Input sequence
item()* Reversed sequence
Examples:
Expression Result
fn:reverse((1, 2, 3, 4)) (4, 3, 2, 1)
fn:reverse(('apple', 'banana', 'orange')) ('orange', 'banana', 'apple')
fn:reverse(('red', 'blue', 'green')) ('green', 'blue', 'red')

W3C Documentation reference: reverse
fn:remove(item()*, xs:integer)
Removes an item from a sequence at the specified position
Arguments and return type:
Type Description
item()* Target sequence
xs:integer Position of the item to remove
item()* New sequence with the item removed
Examples:
Expression Result
fn:remove((1, 2, 3, 4), 2) (1, 3, 4)
fn:remove(('apple', 'banana', 'orange'), 3) ('apple', 'banana')
fn:remove((10, 20, 30), 1) (20, 30)

W3C Documentation reference: remove
fn:insert-before(item()*, xs:integer, item()*)
Inserts items from the specified sequence into another sequence at a given position
Arguments and return type:
Type Description
item()* Target sequence
xs:integer Position at which to insert the items
item()* Sequence of items to insert
item()* New sequence with items inserted
Examples:
Expression Result
fn:insert-before((1, 3, 4), 2, (2)) (1, 2, 3, 4)
fn:insert-before(('apple', 'orange'), 1, ('banana')) ('banana', 'apple', 'orange')
fn:insert-before((10, 20, 30), 4, (40)) (10, 20, 30, 40)

W3C Documentation reference: insert-before
fn:tail(item()*)
Returns all items of the input sequence except the first one, or an empty sequence if the input is empty or contains only one item
Arguments and return type:
Type Description
item()* Sequence of items
item()* All items except the first one, or an empty sequence
Examples:
Expression Result
fn:tail((1, 2, 3)) (2, 3)
fn:tail((1)) ()
fn:tail(/books/book/author) All authors in the "books" element except the first one

W3C Documentation reference: tail
fn:head(item()*)
Returns the first item of the input sequence, or an empty sequence if the input is empty
Arguments and return type:
Type Description
item()* Sequence of items
item()? The first item of the sequence, or an empty sequence
Examples:
Expression Result
fn:head((1, 2, 3)) 1
fn:head(()) ()
fn:head(/books/book[1]/author) The first author of the first book in the "books" element

W3C Documentation reference: head
fn:exists(item()*)
Returns true if the input sequence is not empty, otherwise returns false
Arguments and return type:
Type Description
item()* Sequence of items
xs:boolean Result of the test (true or false)
Examples:
Expression Result
fn:exists((1, 2, 3)) true
fn:exists(()) false
fn:exists(//chapter[5]) true if there are at least 5 chapters, otherwise false

W3C Documentation reference: exists
fn:empty(item()*)
Returns true if the input sequence is empty, otherwise returns false
Arguments and return type:
Type Description
item()* Sequence of items
xs:boolean Result of the test (true or false)
Examples:
Expression Result
fn:empty((1, 2, 3)) false
fn:empty(()) true
fn:empty(//chapter[100]) true if there are less than 100 chapters, otherwise false

W3C Documentation reference: empty
fn:data(item*)
Returns the simple value of an item or a sequence of items
Arguments and return type:
Type Description
item? Returns the simple value of the specified item or the context item (if no argument is provided)
Examples:
Expression Result
fn:data(/library/fiction:book[1]/title) The Catcher in the Rye
fn:data(/library/fiction:book[2]/author) Harper Lee

W3C Documentation reference: Data
fn:implicit-timezone()
Returns the implicit timezone as an xs:dayTimeDuration
Arguments and return type:
Type Description
None Function takes no arguments
xs:dayTimeDuration The implicit timezone as a dayTimeDuration
Examples:
Expression Result
implicit-timezone() Returns the implicit timezone as an xs:dayTimeDuration, e.g., '-PT7H'

W3C Documentation reference: implicit-timezone
fn:current-time()
Returns the current time with timezone
Arguments and return type:
Type Description
None Function takes no arguments
xs:time The current time with timezone
Examples:
Expression Result
current-time() Returns the current time with timezone, e.g., '13:45:30.123-07:00'

W3C Documentation reference: current-time
fn:current-date()
Returns the current date with timezone
Arguments and return type:
Type Description
None Function takes no arguments
xs:date The current date with timezone
Examples:
Expression Result
current-date() Returns the current date with timezone, e.g., '2023-03-29-07:00'

W3C Documentation reference: current-date
fn:current-dateTime()
Returns the current date and time with timezone
Arguments and return type:
Type Description
None Function takes no arguments
xs:dateTime The current date and time with timezone
Examples:
Expression Result
current-dateTime() Returns the current date and time with timezone, e.g., '2023-03-29T12:34:56.789-07:00'

W3C Documentation reference: current-dateTime
fn:format-time(xs:time?, xs:string, xs:string?, xs:string?, xs:string?)
Formats a time value using the provided picture string and optional language, calendar, and country settings
Arguments and return type:
Type Description
xs:time? Time value
xs:string Picture string
xs:string? Language
xs:string? Calendar
xs:string? Country
Examples:
Expression Result
fn:format-time(xs:time('14:30:15'), '[H01]:[m01]:[s01]') 14:30:15
fn:format-time(xs:time('14:30:15'), '[h01] [P] [ZN,*-3]') 02 PM UTC

W3C Documentation reference: Format-Time
fn:format-date(xs:date?, xs:string, xs:string?, xs:string?, xs:string?)
Formats a date value using the provided picture string and optional language, calendar, and country settings
Arguments and return type:
Type Description
xs:date? Date value
xs:string Picture string
xs:string? Language
xs:string? Calendar
xs:string? Country
Examples:
Expression Result
fn:format-date(xs:date('2023-04-01'), '[Y0001]-[M01]-[D01]') 2023-04-01
fn:format-date(xs:date('2023-04-01'), '[MNn,*-3] [D], [Y]') Apr 1, 2023

W3C Documentation reference: Format-Date
fn:format-dateTime(xs:dateTime?, xs:string, xs:string?, xs:string?, xs:string?)
Formats a dateTime value using the provided picture string and optional language, calendar, and country settings
Arguments and return type:
Type Description
xs:dateTime? DateTime value
xs:string Picture string
xs:string? Language
xs:string? Calendar
xs:string? Country
Examples:
Expression Result
fn:format-dateTime(xs:dateTime('2023-04-01T12:00:00'), '[Y0001]-[M01]-[D01] [H01]:[m01]:[s01]') 2023-04-01 12:00:00
fn:format-dateTime(xs:dateTime('2023-04-01T12:00:00'), '[MNn,*-3], [D], [Y]') Apr, 1, 2023

W3C Documentation reference: Format-DateTime
fn:adjust-time-to-timezone(xs:time?, xs:dayTimeDuration?)
Adjusts the timezone of a time value
Arguments and return type:
Type Description
xs:time? Time value
xs:dayTimeDuration? Timezone adjustment
Examples:
Expression Result
fn:adjust-time-to-timezone(xs:time('10:00:00-07:00'), xs:dayTimeDuration('PT2H')) 12:00:00-05:00
fn:adjust-time-to-timezone(xs:time('10:00:00Z'), xs:dayTimeDuration('-PT3H')) 07:00:00-03:00

W3C Documentation reference: Adjust-Time-To-Timezone
fn:adjust-date-to-timezone(xs:date?, xs:dayTimeDuration?)
Adjusts the timezone of a date value
Arguments and return type:
Type Description
xs:date? Date value
xs:dayTimeDuration? Timezone adjustment
Examples:
Expression Result
fn:adjust-date-to-timezone(xs:date('2023-01-01-07:00'), xs:dayTimeDuration('PT2H')) 2023-01-01-05:00
fn:adjust-date-to-timezone(xs:date('2023-01-01Z'), xs:dayTimeDuration('-PT3H')) 2022-12-31-03:00

W3C Documentation reference: Adjust-Date-To-Timezone
fn:adjust-dateTime-to-timezone(xs:dateTime?, xs:dayTimeDuration?)
Adjusts the timezone of a dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
xs:dayTimeDuration? Timezone adjustment
Examples:
Expression Result
fn:adjust-dateTime-to-timezone(xs:dateTime('2023-01-01T12:00:00-07:00'), xs:dayTimeDuration('PT2H')) 2023-01-01T17:00:00-05:00
fn:adjust-dateTime-to-timezone(xs:dateTime('2023-01-01T12:00:00Z'), xs:dayTimeDuration('-PT3H')) 2023-01-01T09:00:00-03:00

W3C Documentation reference: Adjust-DateTime-To-Timezone
fn:timezone-from-time(xs:time?)
Extracts the timezone component from an xs:time value
Arguments and return type:
Type Description
xs:time? Time value
Examples:
Expression Result
fn:timezone-from-time(xs:time('12:00:00-07:00')) -PT7H
fn:timezone-from-time(xs:time('14:30:00+02:30')) PT2H30M

W3C Documentation reference: Timezone-From-Time
fn:seconds-from-time(xs:time?)
Extracts the seconds component from an xs:time value
Arguments and return type:
Type Description
xs:time? Time value
Examples:
Expression Result
fn:seconds-from-time(xs:time('21:45:30.5')) 30.5
fn:seconds-from-time(xs:time('04:15:12.1')) 12.1

W3C Documentation reference: Seconds-From-Time
fn:minutes-from-time(xs:time?)
Extracts the minutes component from an xs:time value
Arguments and return type:
Type Description
xs:time? Time value
Examples:
Expression Result
fn:minutes-from-time(xs:time('21:45:30')) 45
fn:minutes-from-time(xs:time('04:15:12')) 15

W3C Documentation reference: Minutes-From-Time
fn:hours-from-time(xs:time?)
Extracts the hours component from an xs:time value
Arguments and return type:
Type Description
xs:time? Time value
Examples:
Expression Result
fn:hours-from-time(xs:time('21:45:30')) 21
fn:hours-from-time(xs:time('04:15:12')) 4

W3C Documentation reference: Hours-From-Time
fn:timezone-from-date(xs:date?)
Extracts the timezone component from an xs:date value
Arguments and return type:
Type Description
xs:date? Date value
Examples:
Expression Result
fn:timezone-from-date(xs:date('2023-03-29+02:00')) PT2H
fn:timezone-from-date(xs:date('1980-12-15-05:00')) -PT5H

W3C Documentation reference: Timezone-From-Date
fn:day-from-date(xs:date?)
Extracts the day component from an xs:date value
Arguments and return type:
Type Description
xs:date? Date value
Examples:
Expression Result
fn:day-from-date(xs:date('2023-03-29')) 29
fn:day-from-date(xs:date('1980-12-15')) 15

W3C Documentation reference: Day-From-Date
fn:month-from-date(xs:date?)
Extracts the month component from an xs:date value
Arguments and return type:
Type Description
xs:date? Date value
Examples:
Expression Result
fn:month-from-date(xs:date('2023-03-29')) 3
fn:month-from-date(xs:date('1980-12-15')) 12

W3C Documentation reference: Month-From-Date
fn:year-from-date(xs:date?)
Extracts the year component from an xs:date value
Arguments and return type:
Type Description
xs:date? Date value
Examples:
Expression Result
fn:year-from-date(xs:date('2023-03-29')) 2023
fn:year-from-date(xs:date('1980-12-15')) 1980

W3C Documentation reference: Year-From-Date
fn:timezone-from-dateTime(xs:dateTime?)
Extracts the timezone component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:timezone-from-dateTime(xs:dateTime('2023-03-29T12:30:45-07:00')) -PT7H
fn:timezone-from-dateTime(xs:dateTime('2023-12-15T18:45:30+03:30')) PT3H30M

W3C Documentation reference: Timezone-From-DateTime
fn:seconds-from-dateTime(xs:dateTime?)
Extracts the seconds component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:seconds-from-dateTime(xs:dateTime('2023-03-29T12:30:45')) 45
fn:seconds-from-dateTime(xs:dateTime('2023-12-15T18:45:30.5-08:00')) 30.5

W3C Documentation reference: Seconds-From-DateTime
fn:minutes-from-dateTime(xs:dateTime?)
Extracts the minutes component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:minutes-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 30
fn:minutes-from-dateTime(xs:dateTime('2023-12-15T18:45:00-08:00')) 45

W3C Documentation reference: Minutes-From-DateTime
fn:hours-from-dateTime(xs:dateTime?)
Extracts the hours component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:hours-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 12
fn:hours-from-dateTime(xs:dateTime('2023-12-15T18:45:00-08:00')) 18

W3C Documentation reference: Hours-From-DateTime
fn:day-from-dateTime(xs:dateTime?)
Extracts the day component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:day-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 29
fn:day-from-dateTime(xs:dateTime('2023-12-15T18:45:00-08:00')) 15

W3C Documentation reference: Day-From-DateTime
fn:month-from-dateTime(xs:dateTime?)
Extracts the month component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:month-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 3
fn:month-from-dateTime(xs:dateTime('2023-12-15T18:45:00-08:00')) 12

W3C Documentation reference: Month-From-DateTime
fn:year-from-dateTime(xs:dateTime?)
Extracts the year component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:year-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 2023
fn:year-from-dateTime(xs:dateTime('2023-03-29T12:30:00-08:00')) 2023

W3C Documentation reference: Year-From-DateTime
fn:dateTime(xs:date?, xs:time?)
Constructs an xs:dateTime value from an xs:date and an xs:time value
Arguments and return type:
Type Description
xs:date? Date value
xs:time? Time value
Examples:
Expression Result
fn:dateTime(xs:date('2023-03-29'), xs:time('12:30:00')) 2023-03-29T12:30:00
fn:dateTime(xs:date('2023-03-29+05:00'), xs:time('12:30:00-08:00')) 2023-03-29T12:30:00-08:00

W3C Documentation reference: DateTime
fn:seconds-from-duration(xs:duration?)
Returns the seconds component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the seconds component
Examples:
Expression Result
fn:seconds-from-duration(xs:dayTimeDuration('PT1H30M15.5S')) 15.5
fn:seconds-from-duration(xs:dayTimeDuration('-PT2M10.3S')) -10.3

W3C Documentation reference: Seconds-From-Duration
fn:minutes-from-duration(xs:duration?)
Returns the minutes component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the minutes component
Examples:
Expression Result
fn:minutes-from-duration(xs:dayTimeDuration('PT2H30M')) 30
fn:minutes-from-duration(xs:dayTimeDuration('-PT1H45M')) -45

W3C Documentation reference: Minutes-From-Duration
fn:hours-from-duration(xs:duration?)
Returns the hours component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the hours component
Examples:
Expression Result
fn:hours-from-duration(xs:dayTimeDuration('PT36H')) 36
fn:hours-from-duration(xs:dayTimeDuration('-PT12H30M')) -12

W3C Documentation reference: Hours-From-Duration
fn:days-from-duration(xs:duration?)
Returns the days component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the days component
Examples:
Expression Result
fn:days-from-duration(xs:dayTimeDuration('P5DT12H30M')) 5
fn:days-from-duration(xs:dayTimeDuration('-P2DT6H')) -2

W3C Documentation reference: Days-From-Duration
fn:months-from-duration(xs:duration?)
Returns the months component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the months component
Examples:
Expression Result
fn:months-from-duration(xs:duration('P2Y3M4DT5H6M7S')) 3
fn:months-from-duration(xs:duration('-P2Y3M4DT5H6M7S')) -3

W3C Documentation reference: Months-From-Duration
fn:years-from-duration(xs:duration?)
Returns the years component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the years component
Examples:
Expression Result
fn:years-from-duration(xs:duration('P2Y3M4DT5H6M7S')) 2
fn:years-from-duration(xs:duration('-P2Y3M4DT5H6M7S')) -2

W3C Documentation reference: Years-From-Duration
fn:trace(item()*, xs:string)
Outputs the provided label and value for diagnostic purposes and returns the value unchanged
Arguments and return type:
Type Description
item()* Value to be traced
xs:string Label to be output along with the value
Examples:
Expression Result
fn:trace(42, 'The value is:') Outputs "The value is: 42" for diagnostic purposes and returns 42
fn:trace(/library/book/title, 'Book title:') Outputs "Book title: [book title]" for diagnostic purposes and returns the book title

W3C Documentation reference: Trace
fn:error(xs:QName?, xs:string?, $error-object)
Raises an error with the specified error code, description, and error object
Arguments and return type:
Type Description
xs:QName? Error code (optional)
xs:string? Description of the error (optional)
item()* Error object (optional)
Examples:
Expression Result
fn:error(xs:QName('err:FOER0000')) Raise error with the code err:FOER0000
fn:error(xs:QName('err:FOER0000'), 'Invalid value') Raise error with the code err:FOER0000 and description "Invalid value"

W3C Documentation reference: Error
fn:function-arity(function(*))
Returns the arity (number of arguments) of the specified function
Arguments and return type:
Type Description
function(*) The function to obtain the arity for
xs:integer The arity (number of arguments) of the specified function
Examples:
Expression Result
function-arity(fn:substring) Returns the arity of the substring function: 2 (since substring accepts two required arguments: the input string and the starting index)

W3C Documentation reference: function-arity
fn:function-name(function(*))
Returns the QName of the specified function
Arguments and return type:
Type Description
function(*) The function to obtain the QName for
xs:QName? The QName of the specified function, or an empty sequence if the function is anonymous
Examples:
Expression Result
function-name(fn:substring) Returns the QName of the substring function: QName("http://www.w3.org/2005/xpath-functions", "substring")

W3C Documentation reference: function-name
fn:function-lookup(xs:QName, xs:integer)
Returns a function with the specified QName and arity if available, otherwise returns an empty sequence
Arguments and return type:
Type Description
xs:QName Function name as QName
xs:integer Arity of the function
function(*)? A function with the specified QName and arity if available, otherwise an empty sequence
Examples:
Expression Result
function-lookup(QName('http://www.w3.org/2005/xpath-functions', 'substring'), 2) Returns the substring function with arity 2, if available

W3C Documentation reference: function-lookup
fn:static-base-uri()
Returns the static base URI as an xs:anyURI, if available
Arguments and return type:
Type Description
None Function takes no arguments
xs:anyURI? The static base URI, if available; otherwise, an empty sequence
Examples:
Expression Result
static-base-uri() Returns the static base URI as an xs:anyURI, if available, e.g., 'https://www.example.com/base/'

W3C Documentation reference: static-base-uri
fn:default-collation()
Returns the default collation URI as an xs:string
Arguments and return type:
Type Description
None Function takes no arguments
xs:string The default collation URI as a string
Examples:
Expression Result
default-collation() Returns the default collation URI as an xs:string, e.g., 'http://www.w3.org/2005/xpath-functions/collation/codepoint'

W3C Documentation reference: default-collation
fn:serialize(item()?, item()?)
Serializes an XML node, producing a string representation of the node
Arguments and return type:
Type Description
item()? An XML node to serialize
item()? Serialization options as a map, with key-value pairs defining the serialization parameters (optional)
xs:string? A string representation of the serialized XML node or an empty sequence if the input is an empty sequence
Examples:
Expression Result
fn:serialize(<item>Item 1</item>) Returns '<item>Item 1</item>'
fn:serialize(<item>Item 1</item>, map{'method': 'xml', 'indent': 'yes'}) Returns an indented XML string representation of the input node

W3C Documentation reference: serialize
fn:parse-xml-fragment(xs:string?)
Parses a string containing an XML fragment and returns a corresponding document node
Arguments and return type:
Type Description
xs:string? A string containing an XML fragment
document-node(element(*))? A document node containing the parsed XML fragment or an empty sequence if the input is an empty sequence
Examples:
Expression Result
fn:parse-xml-fragment('<item>Item 1</item><item>Item 2</item>') Returns a document node containing the parsed XML fragment

W3C Documentation reference: parse-xml-fragment
fn:parse-xml(xs:string?)
Parses a string containing an XML document and returns a corresponding document node
Arguments and return type:
Type Description
xs:string? A string containing an XML document
document-node(element(*))? A document node containing the parsed XML content or an empty sequence if the input is an empty sequence
Examples:
Expression Result
fn:parse-xml('<root><item>Item 1</item></root>') Returns a document node containing the parsed XML content

W3C Documentation reference: parse-xml
fn:available-environment-variables()
Retrieves a sequence of the names of all available environment variables
Arguments and return type:
Type Description
None No argument is required
xs:string* A sequence of the names of all available environment variables
Examples:
Expression Result
fn:available-environment-variables() Returns a sequence of the names of all available environment variables

W3C Documentation reference: available-environment-variables
fn:environment-variable(xs:string)
Retrieves the value of an environment variable
Arguments and return type:
Type Description
xs:string The name of the environment variable
xs:string? The value of the environment variable, or an empty sequence if the variable is not set
Examples:
Expression Result
fn:environment-variable("PATH") Returns the value of the PATH environment variable, or an empty sequence if the variable is not set

W3C Documentation reference: environment-variable
fn:uri-collection(xs:string?)
Returns a sequence of URIs in a collection identified by a URI
Arguments and return type:
Type Description
xs:string? The URI identifying the collection of URIs
xs:anyURI* A sequence of URIs in the collection
Examples:
Expression Result
fn:uri-collection("http://www.example.com/collection/") Returns a sequence of URIs in the collection identified by the specified URI
fn:uri-collection() Returns a sequence of URIs in the default collection, if one is defined

W3C Documentation reference: uri-collection
fn:doc-available(xs:string?)
Tests whether an XML document is available at a given URI
Arguments and return type:
Type Description
xs:string? The URI of the XML document to be tested
xs:boolean True if the XML document is available, otherwise false
Examples:
Expression Result
fn:doc-available("http://www.example.com/books.xml") Returns true if the XML document located at the specified URI is available, otherwise false
fn:doc-available("") Returns true if the XML document containing the context item is available, otherwise false

W3C Documentation reference: doc-available
fn:doc(xs:string?)
Loads an XML document from a URI and returns the document node
Arguments and return type:
Type Description
xs:string? The URI of the XML document to be loaded
document-node()? The document node of the loaded XML document
Examples:
Expression Result
fn:doc("http://www.example.com/books.xml") Loads the XML document located at the specified URI and returns its document node
fn:doc("") Returns the document node of the XML document containing the context item

W3C Documentation reference: doc
fn:generate-id(node()?)
Returns a unique identifier for the specified node
Arguments and return type:
Type Description
node()? Input node for which the unique identifier is to be generated
xs:string Unique identifier for the specified node
Examples:
Expression Result
fn:generate-id(/bookstore/book[1]) A unique identifier for the first <book> element in the <bookstore>
fn:generate-id(.) A unique identifier for the context node

W3C Documentation reference: generate-id
fn:idref(xs:string*)
Returns a sequence of nodes that are referenced by the specified IDREF attribute values
Arguments and return type:
Type Description
xs:string* Input sequence of IDREF attribute values
node()* Sequence of nodes referenced by the specified IDREF attribute values
Examples:
Expression Result
fn:idref("reference42") Nodes referenced by the IDREF attribute value "reference42"
fn:idref(("ref1", "ref2", "ref3")) Nodes referenced by the IDREF attribute values "ref1", "ref2", and "ref3"

W3C Documentation reference: idref
fn:id(xs:string*)
Returns a sequence of elements with the specified ID attribute values
Arguments and return type:
Type Description
xs:string* Input sequence of ID attribute values
element()* Sequence of elements with the specified ID attribute values
Examples:
Expression Result
fn:id("item42") Element with the ID attribute value "item42"
fn:id(("item1", "item2", "item3")) Elements with the ID attribute values "item1", "item2", and "item3"

W3C Documentation reference: id
fn:lang(xs:string, node()?)
Returns true if the language of the specified node or its nearest ancestor matches the given language code
Arguments and return type:
Type Description
xs:string Language code to test
node()? Optional node
Examples:
Expression Result
fn:lang("en", /book/title) true
fn:lang("fr", /book/title) false

W3C Documentation reference: lang
fn:in-scope-prefixes(element())
Returns a sequence of strings representing the prefixes of the in-scope namespaces for the specified element
Arguments and return type:
Type Description
element() Element node
Examples:
Expression Result
fn:in-scope-prefixes(/*) ("xml", "x")

W3C Documentation reference: in-scope-prefixes
fn:namespace-uri-for-prefix(xs:string?, element())
Returns the namespace URI associated with the given prefix, using the in-scope namespaces for the specified element
Arguments and return type:
Type Description
xs:string? Prefix
element() Element node
Examples:
Expression Result
fn:namespace-uri-for-prefix('x', /*) "http://www.example.com/ns"
fn:namespace-uri-for-prefix('', /*) ""

W3C Documentation reference: namespace-uri-for-prefix
fn:namespace-uri-from-QName(xs:QName?)
Returns the namespace URI of the given QName value, or an empty sequence if there's no namespace URI
Arguments and return type:
Type Description
xs:QName? QName value
Examples:
Expression Result
fn:namespace-uri-from-QName(fn:QName('http://www.example.com/ns', 'x:local')) "http://www.example.com/ns"
fn:namespace-uri-from-QName(fn:QName('', 'local')) ""

W3C Documentation reference: namespace-uri-from-QName
fn:local-name-from-QName(xs:QName?)
Returns the local name of the given QName value, or an empty sequence if there's no local name
Arguments and return type:
Type Description
xs:QName? QName value
Examples:
Expression Result
fn:local-name-from-QName(fn:QName('http://www.example.com/ns', 'x:local')) "local"
fn:local-name-from-QName(fn:QName('', 'local')) "local"

W3C Documentation reference: local-name-from-QName
fn:prefix-from-QName(xs:QName?)
Returns the prefix of the given QName value, or an empty sequence if there's no prefix
Arguments and return type:
Type Description
xs:QName? QName value
Examples:
Expression Result
fn:prefix-from-QName(fn:QName('http://www.example.com/ns', 'x:local')) "x"
fn:prefix-from-QName(fn:QName('', 'local')) ()

W3C Documentation reference: prefix-from-QName
fn:QName(xs:string?, xs:string)
Constructs an xs:QName value from a namespace URI and a lexical QName
Arguments and return type:
Type Description
xs:string? Namespace URI
xs:string Lexical QName
Examples:
Expression Result
fn:QName('http://www.example.com/ns', 'x:local') QName("http://www.example.com/ns", "x:local")
fn:QName('', 'local') QName("", "local")

W3C Documentation reference: QName
fn:resolve-QName(xs:string?, element())
Resolves a QName by expanding a prefix using the in-scope namespaces of a given element
Arguments and return type:
Type Description
xs:string? QName to resolve
element() Element with in-scope namespaces
Examples:
Expression Result
fn:resolve-QName('x:local', $element) QName("http://www.example.com/ns", "local")
fn:resolve-QName('local', $element) QName("", "local")

W3C Documentation reference: Resolve-QName
fn:nilled(node)
Returns a Boolean value indicating whether the argument node is nilled

W3C Documentation reference: #func-nilled
fn:for-each-pair(item()*, item()*, function(item(), item()))
Applies a processing function to pairs of items from two input sequences in a pairwise fashion, resulting in a sequence of the same length as the shorter input sequence
Arguments and return type:
Type Description
item()* The first input sequence of items
item()* The second input sequence of items
function(item(), item()) The processing function used to process pairs of items from the input sequences
item()* The resulting sequence after applying the processing function to pairs of items
Examples:
Expression Result
for-each-pair((1, 2, 3), ("a", "b"), function($item1, $item2) { concat($item1, $item2) }) Returns a sequence with the concatenated pairs of items: ("1a", "2b")

W3C Documentation reference: for-each-pair
fn:filter(item()*, function(item())
Filters a sequence of items based on a given predicate function
Arguments and return type:
Type Description
item()* The input sequence of items
function(item()) The predicate function used to filter the items
item()* The resulting sequence after applying the predicate function
Examples:
Expression Result
filter((1, 2, 3, 4), function($x) { $x mod 2 = 0 }) Returns a new sequence containing only the even numbers from the input sequence: (2, 4)

W3C Documentation reference: filter
fn:for-each(item()*, function(item()))
Applies a specified function to each item in a sequence, returning a new sequence
Arguments and return type:
Type Description
item()* The input sequence of items
function(item()) The function to apply to each item in the sequence
item()* The new sequence created by applying the function to each item in the input sequence
Examples:
Expression Result
for-each((1, 2, 3, 4), function($x) { $x * 2 }) Returns a new sequence with the result of doubling each number in the input sequence: (2, 4, 6, 8)

W3C Documentation reference: for-each
fn:apply(function(item()*), array(*))
Applies a function to a sequence of arguments
Arguments and return type:
Type Description
function(item()*) as item()* The function to be applied
Sequence Sequence of arguments to pass to the function
Examples:
Expression Result
fn:apply(fn:concat#2, ('Hello', ' World')) 'Hello World'
fn:apply(fn:substring#2, ('Hello World', 7)) 'World'

W3C Documentation reference: Apply
fn:outermost(node()*)
Returns the outermost nodes of the input sequence that are not ancestors of any other node in the input sequence
Arguments and return type:
Type Description
node()* Sequence of nodes
Examples:
Expression Result
fn:outermost(//chapter) Sequence of outermost chapter nodes
fn:outermost(/book//*) Sequence of outermost nodes in the book

W3C Documentation reference: outermost
fn:innermost(node()*)
Returns the innermost nodes of the input sequence that are not descendants of any other node in the input sequence
Arguments and return type:
Type Description
node()* Sequence of nodes
Examples:
Expression Result
fn:innermost(//chapter) Sequence of innermost chapter nodes
fn:innermost(/book//*) Sequence of innermost nodes in the book

W3C Documentation reference: innermost
fn:has-children(node()?)
Returns true if the specified node has one or more children, otherwise returns false
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:has-children(/book/chapter[1]) true
fn:has-children(/book/chapter[1]/title) false

W3C Documentation reference: has-children
fn:path(node()?)
Returns a string that represents the path of the specified node within the XML document
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:path(/book/chapter[1]) /book/chapter[1]
fn:path(/book/chapter[2]/title) /book/chapter[2]/title

W3C Documentation reference: path
fn:root(node()?)
Returns the root node of the tree that contains the specified node
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:root(/book/chapter) <book> element (root node)
fn:root(/book/chapter[1]) <book> element (root node)

W3C Documentation reference: root
fn:namespace-uri(node()?)
Returns the namespace URI of the specified node
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:namespace-uri(/example:root) "http://www.example.com/ns"
fn:namespace-uri(/a/b) ""

W3C Documentation reference: namespace-uri
fn:local-name(node()?)
Returns the local part of the name of the specified node
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:local-name(/a/b) "b"
fn:local-name(/example:root) "root"

W3C Documentation reference: local-name
fn:name(node()?)
Returns the expanded QName of the specified node as a string
Arguments and return type:
Type Description
node()? Optional node
Examples:
Expression Result
fn:name(/a/b) "b"
fn:name(/example:root) "example:root"

W3C Documentation reference: name
fn:document-uri(node?)
Returns the document URI of the given node or the context item
Arguments and return type:
Type Description
node? Returns the document URI of the specified node or the context item (if no argument is provided)
Examples:
Expression Result
fn:document-uri(/library/fiction:book[1]) http://example.com/library.xml (assuming the document URI of the first fiction:book element is "http://example.com/library.xml")
fn:document-uri(/library) http://example.com/library.xml (assuming the document URI of the library element is "http://example.com/library.xml")

W3C Documentation reference: Document-URI
fn:base-uri(node?)
Returns the base URI of the node or the context item
Arguments and return type:
Type Description
node? Returns the base URI of the specified node or the context item (if no argument is provided)
Examples:
Expression Result
fn:base-uri(/library/fiction:book[1]) http://example.com/library.xml (assuming the base URI of the first fiction:book element is "http://example.com/library.xml")
fn:base-uri(/library) http://example.com/library.xml (assuming the base URI of the library element is "http://example.com/library.xml")

W3C Documentation reference: Base-URI
fn:node-name(node?)
Returns the name of a node as an xs:QName
Arguments and return type:
Type Description
node? Returns the name of the specified node or the context item if the argument is omitted
Examples:
Expression Result
fn:node-name(/library/*[1]) fiction:book
fn:node-name(/library/fiction:book[1]/title) title

W3C Documentation reference: Node-Name
fn:not(item()*)
Returns the negation of the effective boolean value of the argument
Arguments and return type:
Type Description
item()* Argument whose effective boolean value is to be negated
Examples:
Expression Result
fn:not(1) false
fn:not(0) true
fn:not('') true
fn:not('true') false

W3C Documentation reference: Not
fn:false()
Returns the boolean value false
Arguments and return type:
Type Description
None Returns the boolean value false
Examples:
Expression Result
fn:false() false
//item[fn:false()] Returns an empty node-set

W3C Documentation reference: False
fn:true()
Returns the boolean value true
Arguments and return type:
Type Description
None Returns the boolean value true
Examples:
Expression Result
fn:true() true
//item[fn:true()] Returns all <item> elements

W3C Documentation reference: True
fn:boolean(item()*)
Converts the argument to a boolean value
Arguments and return type:
Type Description
item()* Argument to be converted to a boolean value
Examples:
Expression Result
fn:boolean(1) true
fn:boolean(0) false
fn:boolean('') false
fn:boolean('true') true

W3C Documentation reference: Boolean
fn:unparsed-text-available(xs:string?, xs:string?)
Determines if an unparsed text resource identified by a URI can be read using the given encoding
Arguments and return type:
Type Description
xs:string? The URI identifying the unparsed text resource
xs:string? The encoding to be used for reading the resource
xs:boolean Indicates if the resource can be read using the given encoding
Examples:
Expression Result
fn:unparsed-text-available("http://www.example.com/text.txt", "UTF-8") Returns true if the text resource identified by the specified URI can be read using the specified encoding, otherwise false

W3C Documentation reference: unparsed-text-available
fn:unparsed-text-lines(xs:string?, xs:string?)
Returns the contents of an unparsed text resource identified by a URI, split into lines
Arguments and return type:
Type Description
xs:string? The URI identifying the unparsed text resource
xs:string? The encoding to be used for reading the resource
xs:string* The lines of the unparsed text resource
Examples:
Expression Result
fn:unparsed-text-lines("http://www.example.com/text.txt", "UTF-8") Returns the lines of the text resource identified by the specified URI, using the specified encoding

W3C Documentation reference: unparsed-text-lines
fn:unparsed-text(xs:string?, xs:string?)
Returns the contents of an unparsed text resource identified by a URI
Arguments and return type:
Type Description
xs:string? The URI identifying the unparsed text resource
xs:string? The encoding to be used for reading the resource
xs:string? The contents of the unparsed text resource
Examples:
Expression Result
fn:unparsed-text("http://www.example.com/text.txt", "UTF-8") Returns the contents of the text resource identified by the specified URI, using the specified encoding

W3C Documentation reference: unparsed-text
fn:escape-html-uri(xs:string?)
Escapes special characters in a URI to be used in HTML
Arguments and return type:
Type Description
xs:string? URI to be escaped for use in HTML
Examples:
Expression Result
fn:escape-html-uri('https://example.com/search?q=test&lang=en') https://example.com/search?q=test&lang=en
fn:escape-html-uri('https://example.com/page?id=1§ion=2') https://example.com/page?id=1&section=2

W3C Documentation reference: Escape-HTML-URI
fn:iri-to-uri(xs:string?)
Converts an IRI to a URI by escaping non-ASCII characters
Arguments and return type:
Type Description
xs:string? IRI to be converted to a URI
Examples:
Expression Result
fn:iri-to-uri('https://example.com/ümlaut') https://example.com/%C3%BCmlaut
fn:iri-to-uri('https://example.com/日本語') https://example.com/%E6%97%A5%E6%9C%AC%E8%AA%9E

W3C Documentation reference: IRI-to-URI
fn:encode-for-uri(xs:string?)
Encodes a string for use in a URI by escaping special characters
Arguments and return type:
Type Description
xs:string? String to be encoded for use in a URI
Examples:
Expression Result
fn:encode-for-uri('hello world') hello%20world
fn:encode-for-uri('example?query=value¶m=value2') example%3Fquery%3Dvalue%26param%3Dvalue2

W3C Documentation reference: Encode-for-URI
fn:resolve-uri(xs:string?, xs:string?)
Resolves a relative URI using a base URI
Arguments and return type:
Type Description
xs:string? Relative URI to resolve
xs:string? Base URI to use for resolving (optional)
Examples:
Expression Result
fn:resolve-uri('example.html', 'https://www.example.com/folder/') https://www.example.com/folder/example.html
fn:resolve-uri('../images/pic.jpg', 'https://www.example.com/folder/page.html') https://www.example.com/images/pic.jpg

W3C Documentation reference: Resolve-URI
fn:analyze-string(xs:string?, xs:string, xs:string?)
Analyzes the input string and returns an XML fragment containing match and non-match elements
Arguments and return type:
Type Description
xs:string? Input string to analyze
xs:string Regular expression pattern to match
xs:string? Flags to control the regular expression matching (optional)
Examples:
Expression Result
fn:analyze-string('red,green,blue', ',') <fn:analyze-string-result><fn:non-match>red</fn:non-match><fn:match>, <fn:non-match>green</fn:non-match><fn:match>, <fn:non-match>blue</fn:non-match></fn:analyze-string-result>

W3C Documentation reference: Analyze-String
fn:tokenize(xs:string?, xs:string, xs:string?)
Splits the input string into a sequence of substrings using the pattern as a delimiter
Arguments and return type:
Type Description
xs:string? Input string to tokenize
xs:string Regular expression pattern to use as delimiter
xs:string? Flags to control the regular expression matching (optional)
Examples:
Expression Result
fn:tokenize('XPath 3.0, XQuery 3.0, XSLT 3.0', ',\\s*') ('XPath 3.0', 'XQuery 3.0', 'XSLT 3.0')
fn:tokenize('apple,orange,banana', ',') ('apple', 'orange', 'banana')

W3C Documentation reference: Tokenize
fn:replace(xs:string?, xs:string, xs:string, xs:string?)
Replaces occurrences of the pattern in the input string with the replacement string
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string Regular expression pattern to match
xs:string Replacement string
xs:string? Flags to control the regular expression matching (optional)
Examples:
Expression Result
fn:replace('XPath 3.0 is great', '3.0', '3.1') 'XPath 3.1 is great'
fn:replace('Hello, World!', 'World', 'XPath') 'Hello, XPath!'

W3C Documentation reference: Replace
fn:matches(xs:string?, xs:string, xs:string?)
Returns true if the input string matches the regular expression pattern, otherwise false
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string Regular expression pattern to match
xs:string? Flags to control the regular expression matching (optional)
Examples:
Expression Result
fn:matches('XPath 3.0', '\\d\\.\\d') true
fn:matches('Hello, World!', '[A-Z][a-z]*') true
fn:matches('example123', '\\d+', 'q') false

W3C Documentation reference: Matches
fn:substring-after(xs:string?, xs:string?)
Returns the part of the first string that follows the first occurrence of the second string
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string? Substring to search for
Examples:
Expression Result
fn:substring-after('Hello, World!', ',') ' World!'
fn:substring-after('XPath 3.0 is awesome!', '3.0') ' is awesome!'

W3C Documentation reference: Substring-After
fn:substring-before(xs:string?, xs:string?)
Returns the part of the first string that precedes the first occurrence of the second string
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string? Substring to search for
Examples:
Expression Result
fn:substring-before('Hello, World!', ',') 'Hello'
fn:substring-before('XPath 3.0 is awesome!', '3.0') 'XPath '

W3C Documentation reference: Substring-Before
fn:ends-with(xs:string?, xs:string?)
Returns true if the first string ends with the second string, otherwise false
Arguments and return type:
Type Description
xs:string? Input string to check
xs:string? Substring to check for at the end of the first string
Examples:
Expression Result
fn:ends-with('Hello, World!', 'World!') true
fn:ends-with('Hello, World!', 'Hello') false
fn:ends-with('XPath 3.0', '3.0') true

W3C Documentation reference: Ends-With
fn:starts-with(xs:string?, xs:string?)
Returns true if the first string starts with the second string, otherwise false
Arguments and return type:
Type Description
xs:string? Input string to check
xs:string? Substring to check for at the beginning of the first string
Examples:
Expression Result
fn:starts-with('Hello, World!', 'Hello') true
fn:starts-with('Hello, World!', 'World') false
fn:starts-with('XPath 3.0', 'XPath') true

W3C Documentation reference: Starts-With
fn:contains(xs:string?, xs:string?)
Returns true if the first string contains the second string, otherwise false
Arguments and return type:
Type Description
xs:string? Input string to search within
xs:string? Substring to search for
Examples:
Expression Result
fn:contains('Hello, World!', 'World') true
fn:contains('Hello, World!', 'world') false
fn:contains('XPath 3.0', '3.0') true

W3C Documentation reference: Contains
fn:translate(xs:string?, xs:string, xs:string)
Returns the input string with specified characters replaced
Arguments and return type:
Type Description
xs:string? Input string to be translated
xs:string Map string with characters to replace
xs:string Translate string with replacement characters
Examples:
Expression Result
fn:translate('apple', 'aeiou', '12345') '1ppl2'
fn:translate('Hello, World!', 'HW', 'hw') 'hello, world!'

W3C Documentation reference: Translate
fn:lower-case(xs:string?)
Returns the input string with all characters converted to lowercase
Arguments and return type:
Type Description
xs:string? Input string to convert to lowercase
Examples:
Expression Result
fn:lower-case('HELLO, WORLD!') 'hello, world!'
fn:lower-case('XPath 3.0') 'xpath 3.0'
fn:lower-case('BANANA') 'banana'

W3C Documentation reference: Lower-Case
fn:upper-case(xs:string?)
Returns the input string with all characters converted to uppercase
Arguments and return type:
Type Description
xs:string? Input string to convert to uppercase
Examples:
Expression Result
fn:upper-case('Hello, World!') 'HELLO, WORLD!'
fn:upper-case('XPath 3.0') 'XPATH 3.0'
fn:upper-case('banana') 'BANANA'

W3C Documentation reference: Upper-Case
fn:normalize-unicode(xs:string?, xs:string)
Returns the input string with Unicode normalization applied
Arguments and return type:
Type Description
xs:string? Input string to normalize
xs:string Normalization form to apply (NFC, NFD, NFKC, NFKD)
Examples:
Expression Result
fn:normalize-unicode('Café', 'NFC') 'Café'
fn:normalize-unicode('Café', 'NFD') 'Café'

W3C Documentation reference: Normalize-Unicode
fn:normalize-space(xs:string?)
Returns the input string with whitespace normalized
Arguments and return type:
Type Description
xs:string? Input string to normalize whitespace
Examples:
Expression Result
fn:normalize-space(' Hello, World! ') 'Hello, World!'
fn:normalize-space(' XPath 3.0 ') 'XPath 3.0'
fn:normalize-space('\tbanana\t') 'banana'

W3C Documentation reference: Normalize-Space
fn:string-length(xs:string?)
Returns the length of the input string
Arguments and return type:
Type Description
xs:string? Input string to calculate length
Examples:
Expression Result
fn:string-length('Hello, World!') 13
fn:string-length('XPath 3.0') 8
fn:string-length('banana') 6

W3C Documentation reference: String-Length
fn:substring(xs:string?, xs:double)
Returns a substring of the source string, starting from a specific location
Arguments and return type:
Type Description
xs:string? Input source string
xs:double Starting location to extract the substring
Examples:
Expression Result
fn:substring('Hello, World!', 1, 5) 'Hello'
fn:substring('XPath 3.0', 7) '3.0'
fn:substring('banana', 2, 3) 'ana'

W3C Documentation reference: Substring
fn:string-join(xs:string*, xs:string)
Joins a sequence of strings with a specified separator, returning a single string
Arguments and return type:
Type Description
xs:string* Input sequence of strings to join
xs:string Separator string to insert between joined strings
Examples:
Expression Result
fn:string-join(('apple', 'banana', 'orange'), ', ') 'apple, banana, orange'
fn:string-join(('XPath', '3.0', 'Functions'), ' - ') 'XPath - 3.0 - Functions'
fn:string-join(('A', 'B', 'C'), '') 'ABC'

W3C Documentation reference: String-Join
fn:concat(xs:anyAtomicType?, xs:anyAtomicType?, ...)
Concatenates two or more strings or atomic values, returning a single string
Arguments and return type:
Type Description
xs:anyAtomicType? Input strings or atomic values to concatenate
Examples:
Expression Result
fn:concat('Hello', ' ', 'World') 'Hello World'
fn:concat('I have ', 3, ' apples') 'I have 3 apples'
fn:concat('XPath ', '3.0') 'XPath 3.0'

W3C Documentation reference: Concat
fn:codepoint-equal(xs:string?, xs:string?)
Compares two strings on a codepoint-by-codepoint basis and returns true if they are equal, false otherwise
Arguments and return type:
Type Description
xs:string? First string to compare
xs:string? Second string to compare
Examples:
Expression Result
fn:codepoint-equal('Hello', 'Hello') true
fn:codepoint-equal('Hello', 'hello') false
fn:codepoint-equal('apple', 'banana') false

W3C Documentation reference: Codepoint-Equal
fn:compare(xs:string?, xs:string?)
Compares two strings and returns -1, 0, or 1 if the first string is less than, equal to, or greater than the second string, respectively
Arguments and return type:
Type Description
xs:string? First string to compare
xs:string? Second string to compare
Examples:
Expression Result
fn:compare('apple', 'banana') -1
fn:compare('apple', 'apple') 0
fn:compare('banana', 'apple') 1

W3C Documentation reference: Compare
fn:string-to-codepoints(xs:string?)
Returns a sequence of Unicode code points for a given string
Arguments and return type:
Type Description
xs:string? Input string
Examples:
Expression Result
fn:string-to-codepoints('Hello') (72, 101, 108, 108, 111)
fn:string-to-codepoints('( ͡° ͜ʖ ͡°)') (40, 32, 865, 176, 32, 860, 662, 32, 865, 176, 41)
fn:string-to-codepoints('😊') (128522)

W3C Documentation reference: String-To-Codepoints
fn:codepoints-to-string(xs:integer*)
Constructs a string from a sequence of Unicode code points
Arguments and return type:
Type Description
xs:integer* Sequence of Unicode code points
Examples:
Expression Result
fn:codepoints-to-string((72, 101, 108, 108, 111)) Hello
codepoints-to-string((40, 32, 865, 176, 32, 860, 662, 32, 865, 176, 41)) ( ͡° ͜ʖ ͡°)
fn:codepoints-to-string((128522)) 😊

W3C Documentation reference: Codepoints-To-String
fn:string(object)
Returns the string representation of the object argument
Arguments and return type:
Type Description
string The object to convert to a string
Examples:
Expression Result
string((1<0)) false
string(.11) 0.11

W3C Documentation reference: String-Functions
fn:format-number(numeric?, xs:string, item()?)
Returns a string that represents a formatted version of a number using a formatting pattern and an optional set of properties
Arguments and return type:
Type Description
numeric? The number to format
xs:string The formatting pattern
item()? Optional: the set of properties for formatting the number
xs:string The formatted number as a string
Examples:
Expression Result
format-number(12345.678, "#,##0.00") Returns the formatted number: "12,345.68"
format-number(12345.678, "#,##0") Returns the formatted number: "12,346"
format-number(12345.678, "0.000") Returns the formatted number: "12345.678"

W3C Documentation reference: format-number
fn:format-integer(xs:integer?, xs:string)
Formats an integer value according to the supplied picture string
Arguments and return type:
Type Description
xs:integer? Integer value to be formatted
xs:string Picture string defining the format
Examples:
Expression Result
fn:format-integer(12345, '0,0') 12,345
fn:format-integer(-1234, '0,0') -1,234
fn:format-integer(1234, '00-00-00') 01-23-45

W3C Documentation reference: Format-Integer
fn:round-half-to-even(numeric?)
Returns the closest integer to the given numeric value, rounding half-way cases to the nearest even integer (also known as "bankers' rounding")
Arguments and return type:
Type Description
numeric? Numeric value for which the rounded value will be calculated
Examples:
Expression Result
fn:round-half-to-even(3.5) 4
fn:round-half-to-even(2.5) 2
fn:round-half-to-even(-1.5) -2
fn:round-half-to-even(xs:decimal('1.25'), 1) 1.2

W3C Documentation reference: Round-Half-To-Even
fn:round(numeric?)
Returns the closest integer to the given numeric value, rounding half-way cases away from zero
Arguments and return type:
Type Description
numeric? Numeric value for which the rounded value will be calculated
Examples:
Expression Result
fn:round(3.14) 3
fn:round(-4.7) -5
fn:round(xs:decimal('2.5')) 3

W3C Documentation reference: Round
fn:floor(numeric?)
Returns the largest integer less than or equal to the given numeric value
Arguments and return type:
Type Description
numeric? Numeric value for which the floor value will be calculated
Examples:
Expression Result
fn:floor(3.14) 3
fn:floor(-4.7) -5
fn:floor(xs:decimal('2.5')) 2

W3C Documentation reference: Floor
fn:ceiling(numeric?)
Returns the smallest integer greater than or equal to the given numeric value
Arguments and return type:
Type Description
numeric? Numeric value for which the ceiling value will be calculated
Examples:
Expression Result
fn:ceiling(3.14) 4
fn:ceiling(-4.7) -4
fn:ceiling(xs:decimal('2.5')) 3

W3C Documentation reference: Ceiling
fn:abs(numeric?)
Returns the absolute value of the given numeric value
Arguments and return type:
Type Description
numeric? Numeric value for which the absolute value will be calculated
Examples:
Expression Result
fn:abs(-42) 42
fn:abs(3.14) 3.14
fn:abs(xs:decimal('-5.5')) 5.5

W3C Documentation reference: Abs
fn:number(item?)
Converts the given value to a number
Arguments and return type:
Type Description
item? Returns the numeric value of the specified expression or the context item (if no argument is provided)
Examples:
Expression Result
fn:number(/library/fiction:book[1]/@id) 1 (if the first fiction:book element's id attribute is "1")
fn:number(/library/fiction:book[1]/price) 19.99 (if the first fiction:book element's price element contains "19.99")

W3C Documentation reference: Number
fn:sort(item()*)
Sorts an array of items based on their atomic values
Arguments and return type:
Type Description
Array The array of items to be sorted
Examples:
Expression Result
fn:sort([10, 5, 20]) [5, 10, 20]
fn:sort(['banana', 'apple', 'cherry']) ['apple', 'banana', 'cherry']

W3C Documentation reference: Sort
fn:fold-right(item()*, item()*, function(item(), item()*))
Applies a processing function cumulatively to the items of a sequence from right to left, so as to reduce the sequence to a single value
Arguments and return type:
Type Description
item()* The input sequence of items
item()* The initial value, also known as the zero value
function(item(), item()*) The processing function used to accumulate the items
item()* The resulting single value after applying the processing function
Examples:
Expression Result
fold-right((1, 2, 3, 4), 0, function($current, $accumulator) { $accumulator - $current }) Returns the result of subtracting each number in the input sequence from right to left: -2

W3C Documentation reference: fold-right
fn:fold-left(item()*, item()*, function(item()*, item()))
Applies a processing function cumulatively to the items of a sequence from left to right, so as to reduce the sequence to a single value
Arguments and return type:
Type Description
item()* The input sequence of items
item()* The initial value, also known as the zero value
function(item()*, item()) The processing function used to accumulate the items
item()* The resulting single value after applying the processing function
Examples:
Expression Result
fold-left((1, 2, 3, 4), 0, function($accumulator, $current) { $accumulator + $current }) Returns the sum of the numbers in the input sequence: 10

W3C Documentation reference: fold-left
fn:last()
Returns the position of the last item in the current context sequence
Arguments and return type:
Type Description
None Returns the position of the last item in the current context sequence
Examples:
Expression Result
/library/fiction:book[position() = last()] Returns the last fiction:book element in the library
/library/fiction:book[last()] Returns the last fiction:book element in the library

W3C Documentation reference: Last
fn:position()
Returns the context position of the context item in the sequence currently being processed
Arguments and return type:
Type Description
None Function takes no arguments
xs:integer The position of the context item in the sequence
Examples:
Expression Result
<items><item>Item 1</item><item>Item 2</item></items>/item[position()=2] Returns '<item>Item 2</item>'
<items><item>Item 1</item><item>Item 2</item></items>/item[position()=1] Returns '<item>Item 1</item>'

W3C Documentation reference: position
fn:collection(xs:string?)
Returns a sequence of document nodes obtained from the collection identified by the argument URI, or the default collection if no argument is supplied.
Arguments and return type:
Type Description
xs:string? The URI of the collection to retrieve (Optional)
document-node()* A sequence of document nodes obtained from the collection
Examples:
Expression Result
collection() Returns the sequence of document nodes from the default collection
collection("http://example.com/collection") Returns the sequence of document nodes from the collection identified by the specified URI
count(collection()) Returns the number of document nodes in the default collection

W3C Documentation reference: collection
fn:sum(xs:anyAtomicType*, xs:anyAtomicType?)
Returns the sum of a sequence of numeric values
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of numeric values
xs:anyAtomicType? Value to return if the sequence is empty (optional)
xs:anyAtomicType? Sum of the input sequence
Examples:
Expression Result
fn:sum((10, 20, 30, 40, 50)) 150
fn:sum((), 0) 0

W3C Documentation reference: sum
fn:min(xs:anyAtomicType*)
Returns the minimum value of a sequence of atomic values, according to the ordering rules for the value's type
Arguments and return type:
Type Description
xs:anyAtomicType* The input sequence of atomic values
xs:anyAtomicType? The minimum value of the input sequence, or the empty sequence if the input sequence is empty
Examples:
Expression Result
min((5, 1, 9, 3)) Returns the minimum value: 1
min(()) Returns the empty sequence: ()
min(("apple", "banana", "cherry")) Returns the minimum value (alphabetical order): "apple"

W3C Documentation reference: min
fn:max(xs:anyAtomicType*)
Returns the maximum value of a sequence of atomic values, according to the ordering rules for the value's type
Arguments and return type:
Type Description
xs:anyAtomicType* The input sequence of atomic values
xs:anyAtomicType? The maximum value of the input sequence, or the empty sequence if the input sequence is empty
Examples:
Expression Result
max((5, 1, 9, 3)) Returns the maximum value: 9
max(()) Returns the empty sequence: ()
max(("apple", "banana", "cherry")) Returns the maximum value (alphabetical order): "cherry"

W3C Documentation reference: max
fn:avg(xs:anyAtomicType*)
Computes the average of the numeric values in the input sequence
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of numeric values
xs:anyAtomicType? Average of the numeric values in the input sequence
Examples:
Expression Result
fn:avg((10, 20, 30, 40, 50)) 30
fn:avg((2.5, 3.5, 4.5)) 3.5
fn:avg(()) empty sequence

W3C Documentation reference: avg
fn:count(item()*)
Returns the number of items in the input sequence
Arguments and return type:
Type Description
item()* Input sequence
xs:integer Number of items in the input sequence
Examples:
Expression Result
fn:count(('apple', 'banana', 'orange')) 3
fn:count(()) 0
fn:count((1, 2, 3, 4, 5)) 5

W3C Documentation reference: count
fn:exactly-one(item()*)
Returns the single item in the input sequence or raises an error if the sequence is empty or contains more than one item
Arguments and return type:
Type Description
item()* Input sequence
item() Single item from the input sequence, otherwise an error is raised
Examples:
Expression Result
fn:exactly-one(('apple')) 'apple'
fn:exactly-one(('apple', 'banana')) Error (more than one item)
fn:exactly-one(()) Error (empty sequence)

W3C Documentation reference: exactly-one
fn:one-or-more(item()*)+
Returns the input sequence if it contains one or more items, otherwise raises an error
Arguments and return type:
Type Description
item()* Input sequence
item()+ Sequence containing one or more items, otherwise an error is raised
Examples:
Expression Result
fn:one-or-more(('apple', 'banana')) ('apple', 'banana')
fn:one-or-more(('pear')) ('pear')

W3C Documentation reference: one-or-more
fn:zero-or-one(item()*)
Returns the input sequence if it contains zero or one items, otherwise raises an error
Arguments and return type:
Type Description
item()* Input sequence
item()? Sequence containing zero or one item, otherwise an error is raised
Examples:
Expression Result
fn:zero-or-one(('apple')) ('apple')
fn:zero-or-one(()) ()

W3C Documentation reference: zero-or-one
fn:deep-equal(item()* , item()*)
Returns true if the two input sequences are deep-equal, meaning that they have the same structure and atomic values
Arguments and return type:
Type Description
item()* First input sequence
item()* Second input sequence
xs:boolean True if the input sequences are deep-equal, otherwise false
Examples:
Expression Result
fn:deep-equal((1, 2, 3), (1, 2, 3)) true
fn:deep-equal((1, 2, 3), (1, 2, 4)) false

W3C Documentation reference: deep-equal
fn:index-of(xs:anyAtomicType*, xs:anyAtomicType)
Returns a sequence of integers indicating the positions of items in the input sequence that are equal to the search item
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of atomic values
xs:anyAtomicType Search item to find in the input sequence
xs:integer* Sequence of integers representing the positions of the search item in the input sequence
Examples:
Expression Result
fn:index-of((3, 1, 4, 1, 5, 9, 2, 2, 3), 1) (2, 4)
fn:index-of(('apple', 'banana', 'orange', 'apple', 'grape', 'orange'), 'apple') (1, 4)

W3C Documentation reference: index-of
fn:distinct-values(xs:anyAtomicType*)
Returns a sequence of distinct atomic values from the input sequence
Arguments and return type:
Type Description
xs:anyAtomicType* Input sequence of atomic values
xs:anyAtomicType* Distinct sequence of atomic values
Examples:
Expression Result
fn:distinct-values((3, 1, 4, 1, 5, 9, 2, 2, 3)) (3, 1, 4, 5, 9, 2)
fn:distinct-values(('apple', 'banana', 'orange', 'apple', 'grape', 'orange')) ('apple', 'banana', 'orange', 'grape')

W3C Documentation reference: distinct-values
fn:unordered(item()*)
Returns the items of a sequence in an implementation-dependent order
Arguments and return type:
Type Description
item()* Input sequence
item()* Unordered sequence
Examples:
Expression Result
fn:unordered((3, 1, 4, 1, 5, 9, 2)) (1, 2, 3, 4, 5, 9, 1) (example result; actual order may vary)
fn:unordered(('apple', 'banana', 'orange', 'grape')) ('banana', 'apple', 'orange', 'grape') (example result; actual order may vary)

W3C Documentation reference: unordered
fn:subsequence(item()*, xs:double, xs:double)
Returns a subsequence of a given sequence starting at a specified position with a specified length
Arguments and return type:
Type Description
item()* Input sequence
xs:double Starting position
xs:double Length of subsequence
item()* Subsequence
Examples:
Expression Result
fn:subsequence((1, 2, 3, 4, 5), 2, 3) (2, 3, 4)
fn:subsequence(('apple', 'banana', 'orange', 'grape'), 1, 2) ('apple', 'banana')
fn:subsequence(('red', 'blue', 'green', 'yellow'), 3) ('green', 'yellow')

W3C Documentation reference: subsequence
fn:reverse(item()*)
Reverses the order of items in a sequence
Arguments and return type:
Type Description
item()* Input sequence
item()* Reversed sequence
Examples:
Expression Result
fn:reverse((1, 2, 3, 4)) (4, 3, 2, 1)
fn:reverse(('apple', 'banana', 'orange')) ('orange', 'banana', 'apple')
fn:reverse(('red', 'blue', 'green')) ('green', 'blue', 'red')

W3C Documentation reference: reverse
fn:remove(item()*, xs:integer)
Removes an item from a sequence at the specified position
Arguments and return type:
Type Description
item()* Target sequence
xs:integer Position of the item to remove
item()* New sequence with the item removed
Examples:
Expression Result
fn:remove((1, 2, 3, 4), 2) (1, 3, 4)
fn:remove(('apple', 'banana', 'orange'), 3) ('apple', 'banana')
fn:remove((10, 20, 30), 1) (20, 30)

W3C Documentation reference: remove
fn:insert-before(item()*, xs:integer, item()*)
Inserts items from the specified sequence into another sequence at a given position
Arguments and return type:
Type Description
item()* Target sequence
xs:integer Position at which to insert the items
item()* Sequence of items to insert
item()* New sequence with items inserted
Examples:
Expression Result
fn:insert-before((1, 3, 4), 2, (2)) (1, 2, 3, 4)
fn:insert-before(('apple', 'orange'), 1, ('banana')) ('banana', 'apple', 'orange')
fn:insert-before((10, 20, 30), 4, (40)) (10, 20, 30, 40)

W3C Documentation reference: insert-before
fn:tail(item()*)
Returns all items of the input sequence except the first one, or an empty sequence if the input is empty or contains only one item
Arguments and return type:
Type Description
item()* Sequence of items
item()* All items except the first one, or an empty sequence
Examples:
Expression Result
fn:tail((1, 2, 3)) (2, 3)
fn:tail((1)) ()
fn:tail(/books/book/author) All authors in the "books" element except the first one

W3C Documentation reference: tail
fn:head(item()*)
Returns the first item of the input sequence, or an empty sequence if the input is empty
Arguments and return type:
Type Description
item()* Sequence of items
item()? The first item of the sequence, or an empty sequence
Examples:
Expression Result
fn:head((1, 2, 3)) 1
fn:head(()) ()
fn:head(/books/book[1]/author) The first author of the first book in the "books" element

W3C Documentation reference: head
fn:exists(item()*)
Returns true if the input sequence is not empty, otherwise returns false
Arguments and return type:
Type Description
item()* Sequence of items
xs:boolean Result of the test (true or false)
Examples:
Expression Result
fn:exists((1, 2, 3)) true
fn:exists(()) false
fn:exists(//chapter[5]) true if there are at least 5 chapters, otherwise false

W3C Documentation reference: exists
fn:empty(item()*)
Returns true if the input sequence is empty, otherwise returns false
Arguments and return type:
Type Description
item()* Sequence of items
xs:boolean Result of the test (true or false)
Examples:
Expression Result
fn:empty((1, 2, 3)) false
fn:empty(()) true
fn:empty(//chapter[100]) true if there are less than 100 chapters, otherwise false

W3C Documentation reference: empty
fn:data(item*)
Returns the simple value of an item or a sequence of items
Arguments and return type:
Type Description
item? Returns the simple value of the specified item or the context item (if no argument is provided)
Examples:
Expression Result
fn:data(/library/fiction:book[1]/title) The Catcher in the Rye
fn:data(/library/fiction:book[2]/author) Harper Lee

W3C Documentation reference: Data
fn:implicit-timezone()
Returns the implicit timezone as an xs:dayTimeDuration
Arguments and return type:
Type Description
None Function takes no arguments
xs:dayTimeDuration The implicit timezone as a dayTimeDuration
Examples:
Expression Result
implicit-timezone() Returns the implicit timezone as an xs:dayTimeDuration, e.g., '-PT7H'

W3C Documentation reference: implicit-timezone
fn:current-time()
Returns the current time with timezone
Arguments and return type:
Type Description
None Function takes no arguments
xs:time The current time with timezone
Examples:
Expression Result
current-time() Returns the current time with timezone, e.g., '13:45:30.123-07:00'

W3C Documentation reference: current-time
fn:current-date()
Returns the current date with timezone
Arguments and return type:
Type Description
None Function takes no arguments
xs:date The current date with timezone
Examples:
Expression Result
current-date() Returns the current date with timezone, e.g., '2023-03-29-07:00'

W3C Documentation reference: current-date
fn:current-dateTime()
Returns the current date and time with timezone
Arguments and return type:
Type Description
None Function takes no arguments
xs:dateTime The current date and time with timezone
Examples:
Expression Result
current-dateTime() Returns the current date and time with timezone, e.g., '2023-03-29T12:34:56.789-07:00'

W3C Documentation reference: current-dateTime
fn:format-time(xs:time?, xs:string, xs:string?, xs:string?, xs:string?)
Formats a time value according to a formatting picture string, with optional language, calendar, and country parameters.
Arguments and return type:
Type Description
xs:time? The time value to be formatted (Optional)
xs:string The formatting picture string
xs:string? The language for formatting (Optional)
xs:string? The calendar for formatting (Optional)
xs:string? The country for formatting (Optional)
xs:string The formatted time value as a string
Examples:
Expression Result
format-time(xs:time("14:30:00"), "[H]:[m]") "14:30"
format-time(xs:time("14:30:00"), "[H]:[m]:[s]") "14:30:00"
format-time(xs:time("14:30:00.456"), "[H]:[m]:[s].[f]") "14:30:00.456"

W3C Documentation reference: format-time
fn:format-date(xs:date?, xs:string, xs:string?, xs:string?, xs:string?)
Formats a date value using the provided picture string and optional language, calendar, and country settings
Arguments and return type:
Type Description
xs:date? Date value
xs:string Picture string
xs:string? Language
xs:string? Calendar
xs:string? Country
Examples:
Expression Result
fn:format-date(xs:date('2023-04-01'), '[Y0001]-[M01]-[D01]') 2023-04-01
fn:format-date(xs:date('2023-04-01'), '[MNn,*-3] [D], [Y]') Apr 1, 2023

W3C Documentation reference: Format-Date
fn:format-dateTime(xs:dateTime?, xs:string, xs:string?, xs:string?, xs:string?)
Formats a dateTime value according to a formatting picture string, with optional language, calendar, and country parameters.
Arguments and return type:
Type Description
xs:dateTime? The dateTime value to be formatted (Optional)
xs:string The formatting picture string
xs:string? The language for formatting (Optional)
xs:string? The calendar for formatting (Optional)
xs:string? The country for formatting (Optional)
xs:string The formatted dateTime value as a string
Examples:
Expression Result
format-dateTime(xs:dateTime("2023-04-12T14:30:00"), "[Y]-[M]-[D]T[H]:[m]") "2023-04-12T14:30"
format-dateTime(xs:dateTime("2023-04-12T14:30:00"), "[FNn, Nn] [D] [MNn] [Y]") "Wednesday, 12 April 2023"
format-dateTime(xs:dateTime("2023-04-12T14:30:00.123"), "[Y]-[M]-[D]T[H]:[m]:[s].[f]") "2023-04-12T14:30:00.123"

W3C Documentation reference: format-dateTime
fn:adjust-time-to-timezone(xs:time?, xs:dayTimeDuration?)
Adjusts the timezone of a time value
Arguments and return type:
Type Description
xs:time? Time value
xs:dayTimeDuration? Timezone adjustment
Examples:
Expression Result
fn:adjust-time-to-timezone(xs:time('10:00:00-07:00'), xs:dayTimeDuration('PT2H')) 12:00:00-05:00
fn:adjust-time-to-timezone(xs:time('10:00:00Z'), xs:dayTimeDuration('-PT3H')) 07:00:00-03:00

W3C Documentation reference: Adjust-Time-To-Timezone
fn:adjust-date-to-timezone(xs:date?, xs:dayTimeDuration?)
Adjusts the timezone of a date value
Arguments and return type:
Type Description
xs:date? Date value
xs:dayTimeDuration? Timezone adjustment
Examples:
Expression Result
fn:adjust-date-to-timezone(xs:date('2023-01-01-07:00'), xs:dayTimeDuration('PT2H')) 2023-01-01-05:00
fn:adjust-date-to-timezone(xs:date('2023-01-01Z'), xs:dayTimeDuration('-PT3H')) 2022-12-31-03:00

W3C Documentation reference: Adjust-Date-To-Timezone
fn:adjust-dateTime-to-timezone(xs:dateTime?, xs:dayTimeDuration?)
Adjusts the timezone of a dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
xs:dayTimeDuration? Timezone adjustment
Examples:
Expression Result
fn:adjust-dateTime-to-timezone(xs:dateTime('2023-01-01T12:00:00-07:00'), xs:dayTimeDuration('PT2H')) 2023-01-01T17:00:00-05:00
fn:adjust-dateTime-to-timezone(xs:dateTime('2023-01-01T12:00:00Z'), xs:dayTimeDuration('-PT3H')) 2023-01-01T09:00:00-03:00

W3C Documentation reference: Adjust-DateTime-To-Timezone
fn:timezone-from-time(xs:time?)
Extracts the timezone component from an xs:time value
Arguments and return type:
Type Description
xs:time? Time value
Examples:
Expression Result
fn:timezone-from-time(xs:time('12:00:00-07:00')) -PT7H
fn:timezone-from-time(xs:time('14:30:00+02:30')) PT2H30M

W3C Documentation reference: Timezone-From-Time
fn:seconds-from-time(xs:time?)
Extracts the seconds component from an xs:time value
Arguments and return type:
Type Description
xs:time? Time value
Examples:
Expression Result
fn:seconds-from-time(xs:time('21:45:30.5')) 30.5
fn:seconds-from-time(xs:time('04:15:12.1')) 12.1

W3C Documentation reference: Seconds-From-Time
fn:minutes-from-time(xs:time?)
Extracts the minutes component from an xs:time value
Arguments and return type:
Type Description
xs:time? Time value
Examples:
Expression Result
fn:minutes-from-time(xs:time('21:45:30')) 45
fn:minutes-from-time(xs:time('04:15:12')) 15

W3C Documentation reference: Minutes-From-Time
fn:hours-from-time(xs:time?)
Extracts the hours component from an xs:time value
Arguments and return type:
Type Description
xs:time? Time value
Examples:
Expression Result
fn:hours-from-time(xs:time('21:45:30')) 21
fn:hours-from-time(xs:time('04:15:12')) 4

W3C Documentation reference: Hours-From-Time
fn:timezone-from-date(xs:date?)
Extracts the timezone component from an xs:date value
Arguments and return type:
Type Description
xs:date? Date value
Examples:
Expression Result
fn:timezone-from-date(xs:date('2023-03-29+02:00')) PT2H
fn:timezone-from-date(xs:date('1980-12-15-05:00')) -PT5H

W3C Documentation reference: Timezone-From-Date
fn:day-from-date(xs:date?)
Extracts the day component from an xs:date value
Arguments and return type:
Type Description
xs:date? Date value
Examples:
Expression Result
fn:day-from-date(xs:date('2023-03-29')) 29
fn:day-from-date(xs:date('1980-12-15')) 15

W3C Documentation reference: Day-From-Date
fn:month-from-date(xs:date?)
Extracts the month component from an xs:date value
Arguments and return type:
Type Description
xs:date? Date value
Examples:
Expression Result
fn:month-from-date(xs:date('2023-03-29')) 3
fn:month-from-date(xs:date('1980-12-15')) 12

W3C Documentation reference: Month-From-Date
fn:year-from-date(xs:date?)
Extracts the year component from an xs:date value
Arguments and return type:
Type Description
xs:date? Date value
Examples:
Expression Result
fn:year-from-date(xs:date('2023-03-29')) 2023
fn:year-from-date(xs:date('1980-12-15')) 1980

W3C Documentation reference: Year-From-Date
fn:timezone-from-dateTime(xs:dateTime?)
Extracts the timezone component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:timezone-from-dateTime(xs:dateTime('2023-03-29T12:30:45-07:00')) -PT7H
fn:timezone-from-dateTime(xs:dateTime('2023-12-15T18:45:30+03:30')) PT3H30M

W3C Documentation reference: Timezone-From-DateTime
fn:seconds-from-dateTime(xs:dateTime?)
Extracts the seconds component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:seconds-from-dateTime(xs:dateTime('2023-03-29T12:30:45')) 45
fn:seconds-from-dateTime(xs:dateTime('2023-12-15T18:45:30.5-08:00')) 30.5

W3C Documentation reference: Seconds-From-DateTime
fn:minutes-from-dateTime(xs:dateTime?)
Extracts the minutes component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:minutes-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 30
fn:minutes-from-dateTime(xs:dateTime('2023-12-15T18:45:00-08:00')) 45

W3C Documentation reference: Minutes-From-DateTime
fn:hours-from-dateTime(xs:dateTime?)
Extracts the hours component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:hours-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 12
fn:hours-from-dateTime(xs:dateTime('2023-12-15T18:45:00-08:00')) 18

W3C Documentation reference: Hours-From-DateTime
fn:day-from-dateTime(xs:dateTime?)
Extracts the day component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:day-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 29
fn:day-from-dateTime(xs:dateTime('2023-12-15T18:45:00-08:00')) 15

W3C Documentation reference: Day-From-DateTime
fn:month-from-dateTime(xs:dateTime?)
Extracts the month component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:month-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 3
fn:month-from-dateTime(xs:dateTime('2023-12-15T18:45:00-08:00')) 12

W3C Documentation reference: Month-From-DateTime
fn:year-from-dateTime(xs:dateTime?)
Extracts the year component from an xs:dateTime value
Arguments and return type:
Type Description
xs:dateTime? DateTime value
Examples:
Expression Result
fn:year-from-dateTime(xs:dateTime('2023-03-29T12:30:00')) 2023
fn:year-from-dateTime(xs:dateTime('2023-03-29T12:30:00-08:00')) 2023

W3C Documentation reference: Year-From-DateTime
fn:dateTime(xs:date?, xs:time?)
Constructs an xs:dateTime value from an xs:date and an xs:time value
Arguments and return type:
Type Description
xs:date? Date value
xs:time? Time value
Examples:
Expression Result
fn:dateTime(xs:date('2023-03-29'), xs:time('12:30:00')) 2023-03-29T12:30:00
fn:dateTime(xs:date('2023-03-29+05:00'), xs:time('12:30:00-08:00')) 2023-03-29T12:30:00-08:00

W3C Documentation reference: DateTime
fn:seconds-from-duration(xs:duration?)
Returns the seconds component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the seconds component
Examples:
Expression Result
fn:seconds-from-duration(xs:dayTimeDuration('PT1H30M15.5S')) 15.5
fn:seconds-from-duration(xs:dayTimeDuration('-PT2M10.3S')) -10.3

W3C Documentation reference: Seconds-From-Duration
fn:minutes-from-duration(xs:duration?)
Returns the minutes component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the minutes component
Examples:
Expression Result
fn:minutes-from-duration(xs:dayTimeDuration('PT2H30M')) 30
fn:minutes-from-duration(xs:dayTimeDuration('-PT1H45M')) -45

W3C Documentation reference: Minutes-From-Duration
fn:hours-from-duration(xs:duration?)
Returns the hours component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the hours component
Examples:
Expression Result
fn:hours-from-duration(xs:dayTimeDuration('PT36H')) 36
fn:hours-from-duration(xs:dayTimeDuration('-PT12H30M')) -12

W3C Documentation reference: Hours-From-Duration
fn:days-from-duration(xs:duration?)
Returns the days component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the days component
Examples:
Expression Result
fn:days-from-duration(xs:dayTimeDuration('P5DT12H30M')) 5
fn:days-from-duration(xs:dayTimeDuration('-P2DT6H')) -2

W3C Documentation reference: Days-From-Duration
fn:months-from-duration(xs:duration?)
Returns the months component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the months component
Examples:
Expression Result
fn:months-from-duration(xs:duration('P2Y3M4DT5H6M7S')) 3
fn:months-from-duration(xs:duration('-P2Y3M4DT5H6M7S')) -3

W3C Documentation reference: Months-From-Duration
fn:years-from-duration(xs:duration?)
Returns the years component of the duration
Arguments and return type:
Type Description
xs:duration? Duration from which to extract the years component
Examples:
Expression Result
fn:years-from-duration(xs:duration('P2Y3M4DT5H6M7S')) 2
fn:years-from-duration(xs:duration('-P2Y3M4DT5H6M7S')) -2

W3C Documentation reference: Years-From-Duration
fn:trace(item()*, xs:string)
Outputs the provided label and value for diagnostic purposes and returns the value unchanged
Arguments and return type:
Type Description
item()* Value to be traced
xs:string Label to be output along with the value
Examples:
Expression Result
fn:trace(42, 'The value is:') Outputs "The value is: 42" for diagnostic purposes and returns 42
fn:trace(/library/book/title, 'Book title:') Outputs "Book title: [book title]" for diagnostic purposes and returns the book title

W3C Documentation reference: Trace
fn:error(xs:QName?, xs:string?, $error-object)
Raises an error with the specified error code, description, and error object
Arguments and return type:
Type Description
xs:QName? Error code (optional)
xs:string? Description of the error (optional)
item()* Error object (optional)
Examples:
Expression Result
fn:error(xs:QName('err:FOER0000')) Raise error with the code err:FOER0000
fn:error(xs:QName('err:FOER0000'), 'Invalid value') Raise error with the code err:FOER0000 and description "Invalid value"

W3C Documentation reference: Error
fn:xml-to-json(node(), map(*))
Converts an XML representation of a JSON value to its JSON serialization
Arguments and return type:
Type Description
node() XML representation of a JSON value
map(*) Options for the JSON serialization
Examples:
Expression Result
fn:xml-to-json('<map><string key="name">John</string><number key="age">30</number></map>') '{"name": "John", "age": 30}'
fn:xml-to-json('<array><number>1</number><number>2</number><number>3</number></array>') '[1, 2, 3]'

W3C Documentation reference: XML-to-JSON
fn:json-to-xml(item())
Converts a JSON value to its XML representation
Arguments and return type:
Type Description
item() JSON value to be converted
Examples:
Expression Result
fn:json-to-xml(map{"name": "John", "age": 30}) <map> <string key="name">John</string> <number key="age">30</number> </map>
fn:json-to-xml([1, 2, 3]) <array> <number>1</number> <number>2</number> <number>3</number> </array>

W3C Documentation reference: JSON-to-XML
fn:json-doc(xs:string)
Parses a JSON document from a URI and returns the corresponding value
Arguments and return type:
Type Description
xs:string URI of the JSON document to be parsed
Examples:
Expression Result
fn:json-doc('https://example.com/data.json') Parsed JSON value from the specified URI

W3C Documentation reference: JSON-Doc
fn:parse-json(xs:string?)
Parses a JSON string and returns the corresponding value
Arguments and return type:
Type Description
xs:string? JSON string to be parsed
Examples:
Expression Result
fn:parse-json('{"name": "John", "age": 30}') map{"name": "John", "age": 30}
fn:parse-json('[1, 2, 3]') [1, 2, 3]

W3C Documentation reference: Parse-JSON
fn:function-arity(function(*))
Returns the arity (number of arguments) of the specified function
Arguments and return type:
Type Description
function(*) The function to obtain the arity for
xs:integer The arity (number of arguments) of the specified function
Examples:
Expression Result
function-arity(fn:substring) Returns the arity of the substring function: 2 (since substring accepts two required arguments: the input string and the starting index)

W3C Documentation reference: function-arity
fn:function-name(function(*))
Returns the QName of the specified function
Arguments and return type:
Type Description
function(*) The function to obtain the QName for
xs:QName? The QName of the specified function, or an empty sequence if the function is anonymous
Examples:
Expression Result
function-name(fn:substring) Returns the QName of the substring function: QName("http://www.w3.org/2005/xpath-functions", "substring")

W3C Documentation reference: function-name
fn:function-lookup(xs:QName, xs:integer)
Returns a function with the specified QName and arity if available, otherwise returns an empty sequence
Arguments and return type:
Type Description
xs:QName Function name as QName
xs:integer Arity of the function
function(*)? A function with the specified QName and arity if available, otherwise an empty sequence
Examples:
Expression Result
function-lookup(QName('http://www.w3.org/2005/xpath-functions', 'substring'), 2) Returns the substring function with arity 2, if available

W3C Documentation reference: function-lookup
fn:static-base-uri()
Returns the static base URI as an xs:anyURI, if available
Arguments and return type:
Type Description
None Function takes no arguments
xs:anyURI? The static base URI, if available; otherwise, an empty sequence
Examples:
Expression Result
static-base-uri() Returns the static base URI as an xs:anyURI, if available, e.g., 'https://www.example.com/base/'

W3C Documentation reference: static-base-uri
fn:default-collation()
Returns the default collation URI as an xs:string
Arguments and return type:
Type Description
None Function takes no arguments
xs:string The default collation URI as a string
Examples:
Expression Result
default-collation() Returns the default collation URI as an xs:string, e.g., 'http://www.w3.org/2005/xpath-functions/collation/codepoint'

W3C Documentation reference: default-collation
fn:serialize(item()?, item()?)
Serializes an XML node, producing a string representation of the node
Arguments and return type:
Type Description
item()? An XML node to serialize
item()? Serialization options as a map, with key-value pairs defining the serialization parameters (optional)
xs:string? A string representation of the serialized XML node or an empty sequence if the input is an empty sequence
Examples:
Expression Result
fn:serialize(<item>Item 1</item>) Returns '<item>Item 1</item>'
fn:serialize(<item>Item 1</item>, map{'method': 'xml', 'indent': 'yes'}) Returns an indented XML string representation of the input node

W3C Documentation reference: serialize
fn:parse-xml-fragment(xs:string?)
Parses a string containing an XML fragment and returns a corresponding document node
Arguments and return type:
Type Description
xs:string? A string containing an XML fragment
document-node(element(*))? A document node containing the parsed XML fragment or an empty sequence if the input is an empty sequence
Examples:
Expression Result
fn:parse-xml-fragment('<item>Item 1</item><item>Item 2</item>') Returns a document node containing the parsed XML fragment

W3C Documentation reference: parse-xml-fragment
fn:parse-xml(xs:string?)
Parses a string containing an XML document and returns a corresponding document node
Arguments and return type:
Type Description
xs:string? A string containing an XML document
document-node(element(*))? A document node containing the parsed XML content or an empty sequence if the input is an empty sequence
Examples:
Expression Result
fn:parse-xml('<root><item>Item 1</item></root>') Returns a document node containing the parsed XML content

W3C Documentation reference: parse-xml
fn:available-environment-variables()
Retrieves a sequence of the names of all available environment variables
Arguments and return type:
Type Description
None No argument is required
xs:string* A sequence of the names of all available environment variables
Examples:
Expression Result
fn:available-environment-variables() Returns a sequence of the names of all available environment variables

W3C Documentation reference: available-environment-variables
fn:environment-variable(xs:string)
Retrieves the value of an environment variable
Arguments and return type:
Type Description
xs:string The name of the environment variable
xs:string? The value of the environment variable, or an empty sequence if the variable is not set
Examples:
Expression Result
fn:environment-variable("PATH") Returns the value of the PATH environment variable, or an empty sequence if the variable is not set

W3C Documentation reference: environment-variable
fn:uri-collection(xs:string?)
Returns a sequence of URIs in a collection identified by a URI
Arguments and return type:
Type Description
xs:string? The URI identifying the collection of URIs
xs:anyURI* A sequence of URIs in the collection
Examples:
Expression Result
fn:uri-collection("http://www.example.com/collection/") Returns a sequence of URIs in the collection identified by the specified URI
fn:uri-collection() Returns a sequence of URIs in the default collection, if one is defined

W3C Documentation reference: uri-collection
fn:doc-available(xs:string?)
Tests whether an XML document is available at a given URI
Arguments and return type:
Type Description
xs:string? The URI of the XML document to be tested
xs:boolean True if the XML document is available, otherwise false
Examples:
Expression Result
fn:doc-available("http://www.example.com/books.xml") Returns true if the XML document located at the specified URI is available, otherwise false
fn:doc-available("") Returns true if the XML document containing the context item is available, otherwise false

W3C Documentation reference: doc-available
fn:doc(xs:string?)
Loads an XML document from a URI and returns the document node
Arguments and return type:
Type Description
xs:string? The URI of the XML document to be loaded
document-node()? The document node of the loaded XML document
Examples:
Expression Result
fn:doc("http://www.example.com/books.xml") Loads the XML document located at the specified URI and returns its document node
fn:doc("") Returns the document node of the XML document containing the context item

W3C Documentation reference: doc
fn:generate-id(node()?)
Returns a unique identifier for the specified node
Arguments and return type:
Type Description
node()? Input node for which the unique identifier is to be generated
xs:string Unique identifier for the specified node
Examples:
Expression Result
fn:generate-id(/bookstore/book[1]) A unique identifier for the first <book> element in the <bookstore>
fn:generate-id(.) A unique identifier for the context node

W3C Documentation reference: generate-id
fn:idref(xs:string*)
Returns a sequence of nodes that are referenced by the specified IDREF attribute values
Arguments and return type:
Type Description
xs:string* Input sequence of IDREF attribute values
node()* Sequence of nodes referenced by the specified IDREF attribute values
Examples:
Expression Result
fn:idref("reference42") Nodes referenced by the IDREF attribute value "reference42"
fn:idref(("ref1", "ref2", "ref3")) Nodes referenced by the IDREF attribute values "ref1", "ref2", and "ref3"

W3C Documentation reference: idref
fn:id(xs:string*)
Returns a sequence of elements with the specified ID attribute values
Arguments and return type:
Type Description
xs:string* Input sequence of ID attribute values
element()* Sequence of elements with the specified ID attribute values
Examples:
Expression Result
fn:id("item42") Element with the ID attribute value "item42"
fn:id(("item1", "item2", "item3")) Elements with the ID attribute values "item1", "item2", and "item3"

W3C Documentation reference: id
fn:lang(xs:string, node()?)
Returns true if the language of the specified node or its nearest ancestor matches the given language code
Arguments and return type:
Type Description
xs:string Language code to test
node()? Optional node
Examples:
Expression Result
fn:lang("en", /book/title) true
fn:lang("fr", /book/title) false

W3C Documentation reference: lang
fn:in-scope-prefixes(element())
Returns a sequence of strings representing the prefixes of the in-scope namespaces for the specified element
Arguments and return type:
Type Description
element() Element node
Examples:
Expression Result
fn:in-scope-prefixes(/*) ("xml", "x")

W3C Documentation reference: in-scope-prefixes
fn:namespace-uri-for-prefix(xs:string?, element())
Returns the namespace URI associated with the given prefix, using the in-scope namespaces for the specified element
Arguments and return type:
Type Description
xs:string? Prefix
element() Element node
Examples:
Expression Result
fn:namespace-uri-for-prefix('x', /*) "http://www.example.com/ns"
fn:namespace-uri-for-prefix('', /*) ""

W3C Documentation reference: namespace-uri-for-prefix
fn:namespace-uri-from-QName(xs:QName?)
Returns the namespace URI of the given QName value, or an empty sequence if there's no namespace URI
Arguments and return type:
Type Description
xs:QName? QName value
Examples:
Expression Result
fn:namespace-uri-from-QName(fn:QName('http://www.example.com/ns', 'x:local')) "http://www.example.com/ns"
fn:namespace-uri-from-QName(fn:QName('', 'local')) ""

W3C Documentation reference: namespace-uri-from-QName
fn:local-name-from-QName(xs:QName?)
Returns the local name of the given QName value, or an empty sequence if there's no local name
Arguments and return type:
Type Description
xs:QName? QName value
Examples:
Expression Result
fn:local-name-from-QName(fn:QName('http://www.example.com/ns', 'x:local')) "local"
fn:local-name-from-QName(fn:QName('', 'local')) "local"

W3C Documentation reference: local-name-from-QName
fn:prefix-from-QName(xs:QName?)
Returns the prefix of the given QName value, or an empty sequence if there's no prefix
Arguments and return type:
Type Description
xs:QName? QName value
Examples:
Expression Result
fn:prefix-from-QName(fn:QName('http://www.example.com/ns', 'x:local')) "x"
fn:prefix-from-QName(fn:QName('', 'local')) ()

W3C Documentation reference: prefix-from-QName
fn:QName(xs:string?, xs:string)
Constructs an xs:QName value from a namespace URI and a lexical QName
Arguments and return type:
Type Description
xs:string? Namespace URI
xs:string Lexical QName
Examples:
Expression Result
fn:QName('http://www.example.com/ns', 'x:local') QName("http://www.example.com/ns", "x:local")
fn:QName('', 'local') QName("", "local")

W3C Documentation reference: QName
fn:resolve-QName(xs:string?, element())
Resolves a QName by expanding a prefix using the in-scope namespaces of a given element
Arguments and return type:
Type Description
xs:string? QName to resolve
element() Element with in-scope namespaces
Examples:
Expression Result
fn:resolve-QName('x:local', $element) QName("http://www.example.com/ns", "local")
fn:resolve-QName('local', $element) QName("", "local")

W3C Documentation reference: Resolve-QName
fn:nilled(node)
Returns a Boolean value indicating whether the argument node is nilled

W3C Documentation reference: #func-nilled
fn:for-each-pair(item()*, item()*, function(item(), item()))
Applies a processing function to pairs of items from two input sequences in a pairwise fashion, resulting in a sequence of the same length as the shorter input sequence
Arguments and return type:
Type Description
item()* The first input sequence of items
item()* The second input sequence of items
function(item(), item()) The processing function used to process pairs of items from the input sequences
item()* The resulting sequence after applying the processing function to pairs of items
Examples:
Expression Result
for-each-pair((1, 2, 3), ("a", "b"), function($item1, $item2) { concat($item1, $item2) }) Returns a sequence with the concatenated pairs of items: ("1a", "2b")

W3C Documentation reference: for-each-pair
fn:filter(item()*, function(item())
Filters a sequence of items based on a given predicate function
Arguments and return type:
Type Description
item()* The input sequence of items
function(item()) The predicate function used to filter the items
item()* The resulting sequence after applying the predicate function
Examples:
Expression Result
filter((1, 2, 3, 4), function($x) { $x mod 2 = 0 }) Returns a new sequence containing only the even numbers from the input sequence: (2, 4)

W3C Documentation reference: filter
fn:for-each(item()*, function(item()))
Applies a specified function to each item in a sequence, returning a new sequence
Arguments and return type:
Type Description
item()* The input sequence of items
function(item()) The function to apply to each item in the sequence
item()* The new sequence created by applying the function to each item in the input sequence
Examples:
Expression Result
for-each((1, 2, 3, 4), function($x) { $x * 2 }) Returns a new sequence with the result of doubling each number in the input sequence: (2, 4, 6, 8)

W3C Documentation reference: for-each