# Online XPath tester

Select XPath processor:
XPath version:
Insert your XML:
Insert your XPath:
Transform result:

## 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.

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: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:last()`
Returns the position of the last node in the context list
`W3C Documentation reference: Node-Set-Functions`
`fn:boolean(object)`
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 and return type:

Type | Description
--- | ---
object | The object to convert to a boolean

Examples:

Expression | Result
--- | ---
boolean("Release11") | true
boolean("") | false

`W3C Documentation reference: Boolean-Functions`
`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:number(object)`
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 and return type:

Type | Description
--- | ---
object | The object to convert to a number

Examples:

Expression | Result
--- | ---
boolean("Release11") | true
boolean("") | false

`W3C Documentation reference: Numeric-Functions`
`fn:adjust-date-to-timezone(date,timezone)`
If the timezone argument is empty, it returns a date without a timezone. Otherwise, it returns a date with a timezone
Arguments and return type:

Type | Description
--- | ---
date | date to be adjusted
timezone | timezone to be imposed into date

Examples:

Expression | Result
--- | ---
adjust-date-to-timezone(xs:date('2011-11-15'), xs:dayTimeDuration("PT10H")) | 2011-11-15+10:00

`W3C Documentation reference: #func-adjust-date-to-timezone`
`fn:error()`
https://www.w3.org/TR/xpath-functions/#func-error
`W3C Documentation reference: #func-error`
`fn:nilled(node)`
Returns a Boolean value indicating whether the argument node is nilled
`W3C Documentation reference: #func-nilled`
`fn:for-each(sequence*, function)`
Applies function item to every element in sequence
`W3C Documentation reference: #func-for-each`