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.

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(node-set)
Returns the number of nodes in the node-set
Arguments and return type:
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(object)
Returns the element specified by it's unique id, requires DTD

W3C Documentation reference: Node-Set-Functions
fn:local-name(node-set)
Returns the local-name for the first node in the node-set
Arguments and return type:
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(node-set)
Returns the namespace-uri for the first node in the node-set
Arguments and return type:
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(node-set)
Returns the name for the first node in the node-set
Arguments and return type:
Type Description
node-set 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:name()
Returns the name for the context node
Examples:
Expression Result
current context node Extract first node and return QName

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: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(string)
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 and return type:
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>

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: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:codepoint-equal()
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:lower-case()
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: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()
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: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