http://www.w3.org/2005/xpath-functions

View as XML or JSON.

This module contains all the functions specified in the W3C XPath and XQuery Functions and Operators 3.0.

Function Summary

QName ($paramURI as xs:string?, $paramQName as xs:string) as xs:QName external

Constructs an xs:QName value given a namespace URI and a lexical QName.

abs ($arg as numeric?) as numeric? external

Returns the absolute value of $arg .

adjust-date-to-timezone ($arg as xs:date?) as xs:date? external

Adjusts an xs:date value to a specific timezone, or to no timezone at all; the result is the date in the target timezone that contains the starting instant of the supplied date.

adjust-date-to-timezone ($arg as xs:date?, $timezone as xs:dayTimeDuration?) as xs:date? external

Adjusts an xs:date value to a specific timezone, or to no timezone at all; the result is the date in the target timezone that contains the starting instant of the supplied date.

adjust-dateTime-to-timezone ($arg as xs:dateTime?) as xs:dateTime external

Adjusts an xs:dateTime value to a specific timezone, or to no timezone at all.

adjust-dateTime-to-timezone ($arg as xs:dateTime?, $timezone as xs:dayTimeDuration?) as xs:dateTime external

Adjusts an xs:dateTime value to a specific timezone, or to no timezone at all.

adjust-time-to-timezone ($arg as xs:time?) as xs:time? external

Adjusts an xs:time value to a specific timezone, or to no timezone at all.

adjust-time-to-timezone ($arg as xs:time?, $timezone as xs:dayTimeDuration?) as xs:time? external

Adjusts an xs:time value to a specific timezone, or to no timezone at all.

analyze-string ($input as xs:string?, $pattern as xs:string) as element(fn:analyze-string-result) external

Analyzes a string using a regular expression, returning an XML structure that identifies which parts of the input string matched or failed to match the regular expression, and in the case of matched substrings, which substrings matched each capturing group in the regular expression.

analyze-string ($input as xs:string?, $pattern as xs:string, $flags as xs:string) as element(fn:analyze-string-result) external

Analyzes a string using a regular expression, returning an XML structure that identifies which parts of the input string matched or failed to match the regular expression, and in the case of matched substrings, which substrings matched each capturing group in the regular expression.

available-environment-variables () as xs:string* external

Returns a list of environment variable names that are suitable for passing to fn:environment-variable , as a (possibly empty) sequence of strings.

available-environment-variables () as xs:string* external

Returns a list of environment variable names that are suitable for passing to fn:environment-variable , as a (possibly empty) sequence of strings.

avg ($arg as xs:anyAtomicType*) as xs:anyAtomicType? external

Returns the average of the values in the input sequence $arg , that is, the sum of the values divided by the number of values.

base-uri () as xs:anyURI? external

Returns the base URI of a node.

base-uri ($arg as node()?) as xs:anyURI? external

Returns the base URI of a node.

boolean ($arg as item()*) as xs:boolean external

Computes the effective boolean value of the sequence $arg .

ceiling ($arg as numeric?) as numeric? external

Rounds $arg upwards to a whole number.

codepoint-equal ($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:boolean? external

Returns true if two strings are equal, considered codepoint-by-codepoint.

codepoints-to-string ($arg as xs:integer*) as xs:string external

Creates an xs:string from a sequence of codepoints .

codepoints-to-string ($arg as xs:integer*) as xs:string external

Creates an xs:string from a sequence of codepoints .

collection () as node()* external

Returns a sequence of nodes representing a collection of documents indentified by a collection URI; or a default collection if no URI is supplied.

collection ($arg as xs:string?) as node()* external

Returns a sequence of nodes representing a collection of documents indentified by a collection URI; or a default collection if no URI is supplied.

compare ($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer? external

Returns -1, 0, or 1, depending on whether $comparand1 collates before, equal to, or after $comparand2 according to the rules of a selected collation.

compare ($comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer? external

Returns -1, 0, or 1, depending on whether $comparand1 collates before, equal to, or after $comparand2 according to the rules of a selected collation.

concat ($arg1 as xs:anyAtomicType?, $arg2 as xs:anyAtomicType?) as xs:string external

Returns the concatenation of the string values of the arguments.

contains ($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a substring, taking collations into account.

contains ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a substring, taking collations into account.

count ($arg as item()*) as xs:integer external

Returns the number of items in a sequence.

current-date () as xs:date external

Returns the current date.

current-dateTime () as xs:dateTimeStamp external

Returns the current date and time (with timezone).

current-time () as xs:time external

Returns the current time.

data () as xs:anyAtomicType* external

Returns the result of atomizing a sequence, that is, replacing all nodes in the sequence by their typed values.

data ($arg as item()*) as xs:anyAtomicType* external

Returns the result of atomizing a sequence, that is, replacing all nodes in the sequence by their typed values.

dateTime ($arg1 as xs:date?, $arg2 as xs:time?) as xs:dateTime? external

Returns an xs:dateTime value created by combining an xs:date and an xs:time .

day-from-date ($arg as xs:date?) as xs:integer? external

Returns the day component of an xs:date .

days-from-duration ($arg as xs:duration?) as xs:integer? external

Returns the number of days in a duration.

deep-equal ($parameter1 as item()*, $parameter2 as item()*) as xs:boolean external

This function assesses whether two sequences are deep-equal to each other.

deep-equal ($parameter1 as item()*, $parameter2 as item()*, $collation as xs:string) as xs:boolean external

This function assesses whether two sequences are deep-equal to each other.

default-collation () as xs:string external

Returns the value of the default collation property from the static context.

distinct-values ($arg as xs:anyAtomicType*) as xs:anyAtomicType* external

Returns the values that appear in a sequence, with duplicates eliminated.

distinct-values ($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType* external

Returns the values that appear in a sequence, with duplicates eliminated.

doc-available ($uri as xs:string?) as xs:boolean external

The function returns true if and only if the function call fn:doc($uri) would return a document node.

doc ($uri as xs:string?) as document()? external

Retrieves a document using a URI supplied as an xs:string , and returns the corresponding document node.

document-uri () as xs:anyURI? external

Returns the URI of a resource where a document can be found, if available.

document-uri ($arg as node()?) as xs:anyURI? external

Returns the URI of a resource where a document can be found, if available.

element-with-id ($arg as xs:string*) as element(*)* external

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 .

element-with-id ($arg as xs:string*, $node as node()) as element(*)* external

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 .

empty ($arg as item()*) as xs:boolean external

Returns true if the argument is the empty sequence.

encode-for-uri ($uri-part as xs:string?) as xs:string external

Encodes reserved characters in a string that is intended to be used in the path segment of a URI.

ends-with ($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a trailing substring, taking collations into account.

ends-with ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a trailing substring, taking collations into account.

environment-variable ($name as xs:string) as xs:string? external

Returns the value of a system environment variable, if it exists.

environment-variable ($arg as xs:string) as xs:string? external

Returns the value of a system environment variable, if it exists.

error () as none external

Calling the fn:error function raises an application-defined error.

error ($code as xs:QName) as none external

Calling the fn:error function raises an application-defined error.

error ($code as xs:QName?, $description as xs:string) as none external

Calling the fn:error function raises an application-defined error.

error ($code as xs:QName?, $description as xs:string, $error-object as item()*) as none external

Calling the fn:error function raises an application-defined error.

escape-html-uri ($uri as xs:string?) as xs:string external

Escapes a URI in the same way that HTML user agents handle attribute values expected to contain URIs.

exactly-one ($arg as item()*) as item() external

Returns $arg if it contains exactly one item.

exists ($arg as item()*) as xs:boolean external

Returns true if the argument is a non-empty sequence.

false () as xs:boolean external

Returns the xs:boolean value false .

filter ($seq as item()*, $f as function (item()) as xs:boolean) as item()* external

Returns those items from the sequence $seq for which the supplied function $f returns true.

floor ($arg as numeric?) as numeric? external

Rounds $arg downwards to a whole number.

fold-left ($seq as item()*, $zero as item()*, $f as function (item()*, item()) as item()*) as item()* external

Processes the supplied sequence from left to right, applying the supplied function repeatedly to each item in turn, together with an accumulated result value.

fold-right ($seq as item()*, $zero as item()*, $f as function (item()*, item()) as item()*) as item()* external

Processes the supplied sequence from right to left, applying the supplied function repeatedly to each item in turn, together with an accumulated result value.

for-each-pair ($seq1 as item()*, $seq2 as item()*, $f as function (item(), item()) as item()*) as item()* external

Applies the function item $f to successive pairs of items taken one from $seq1 and one from $seq2 , returning the concatenation of the resulting sequences in order.

for-each ($seq as item()*, $f as function (item()) as item()*) as item()* external

Applies the function item $f to every item from the sequence $seq in turn, returning the concatenation of the resulting sequences in order.

format-date ($value as xs:date?, $picture as xs:string) as xs:string? external

Returns a string containing an xs:date value formatted for display.

format-date ($value as xs:date?, $picture as xs:string, $language as xs:string?, $calendar as xs:string?, $place as xs:string?) as xs:string? external

Returns a string containing an xs:date value formatted for display.

format-dateTime ($value as xs:dateTime?, $picture as xs:string) as xs:string? external

Returns a string containing an xs:dateTime value formatted for display.

format-dateTime ($value as xs:dateTime?, $picture as xs:string, $language as xs:string?, $calendar as xs:string?, $place as xs:string?) as xs:string? external

Returns a string containing an xs:dateTime value formatted for display.

format-integer ($value as xs:integer?, $picture as xs:string) as xs:string external

Formats an integer according to a given picture string, using the conventions of a given natural language if specified.

format-integer ($value as xs:integer?, $picture as xs:string, $language as xs:string) as xs:string external

Formats an integer according to a given picture string, using the conventions of a given natural language if specified.

format-number ($value as numeric?, $picture as xs:string) as xs:string external

Returns a string containing a number formatted according to a given picture string, taking account of decimal formats specified in the static context.

format-number ($value as numeric?, $picture as xs:string, $decimal-format-name as xs:string) as xs:string external

Returns a string containing a number formatted according to a given picture string, taking account of decimal formats specified in the static context.

format-time ($value as xs:time?, $picture as xs:string) as xs:string? external

Returns a string containing an xs:time value formatted for display.

format-time ($value as xs:time?, $picture as xs:string, $language as xs:string?, $calendar as xs:string?, $place as xs:string?) as xs:string? external

Returns a string containing an xs:time value formatted for display.

function-arity ($func as function (*)) as xs:integer external

Returns the arity of the function identified by a function item.

generate-id () as xs:string external

This function returns a string that uniquely identifies a given node.

generate-id ($arg as node()?) as xs:string external

This function returns a string that uniquely identifies a given node.

has-children () as xs:boolean external

Returns true if the supplied node has one or more child nodes (of any kind).

has-children ($node as node()?) as xs:boolean external

Returns true if the supplied node has one or more child nodes (of any kind).

head ($arg as item()*) as item()? external

Returns the first item in a sequence.

hours-from-duration ($arg as xs:duration?) as xs:integer? external

Returns the number of hours in a duration.

hours-from-time ($arg as xs:time?) as xs:integer? external

Returns the hours component of an xs:time .

id ($arg as xs:string*) as element(*)* external

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 .

id ($arg as xs:string*, $node as node()) as element(*)* external

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 .

idref ($arg as xs:string*) as node()* external

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 .

idref ($arg as xs:string*, $node as node()) as node()* external

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 .

implicit-timezone () as xs:dayTimeDuration external

Returns the value of the implicit timezone property from the dynamic context.

in-scope-prefixes ($element as element(*)) as xs:string* external

Returns the prefixes of the in-scope namespaces for an element node.

index-of ($seq as xs:anyAtomicType*, $search as xs:anyAtomicType) as xs:integer* external

Returns a sequence of positive integers giving the positions within the sequence $seq of items that are equal to $search .

index-of ($seq as xs:anyAtomicType*, $search as xs:anyAtomicType, $collation as xs:string) as xs:integer* external

Returns a sequence of positive integers giving the positions within the sequence $seq of items that are equal to $search .

innermost ($nodes as node()*) as node()* external

Returns every node within the input sequence that is not an ancestor of another member of the input sequence; the nodes are returned in document order with duplicates eliminated.

insert-before ($target as item()*, $position as xs:integer, $inserts as item()*) as item()* external

Returns a sequence constructed by inserting an item or a sequence of items at a given position within an existing sequence.

iri-to-uri ($iri as xs:string?) as xs:string external

Converts a string containing an IRI into a URI according to the rules of .

lang ($testlang as xs:string?) as xs:boolean external

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 .

lang ($testlang as xs:string?, $node as node()) as xs:boolean external

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 .

last () as xs:integer external

Returns the context size from the dynamic context.

local-name-from-QName ($arg as xs:QName?) as xs:NCName? external

Returns the local part of the supplied QName.

local-name () as xs:string external

Returns the local part of the name of $arg as an xs:string that is either the zero-length string, or has the lexical form of an xs:NCName .

local-name ($arg as node()?) as xs:string external

Returns the local part of the name of $arg as an xs:string that is either the zero-length string, or has the lexical form of an xs:NCName .

lower-case ($arg as xs:string?) as xs:string external

Converts a string to lower case.

matches ($input as xs:string?, $pattern as xs:string) as xs:boolean external

Returns true if the supplied string matches a given regular expression.

matches ($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:boolean external

Returns true if the supplied string matches a given regular expression.

max ($arg as xs:anyAtomicType*) as xs:anyAtomicType? external

Returns a value that is equal to the highest value appearing in the input sequence.

max ($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType? external

Returns a value that is equal to the highest value appearing in the input sequence.

min ($arg as xs:anyAtomicType*) as xs:anyAtomicType? external

Returns a value that is equal to the lowest value appearing in the input sequence.

min ($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType? external

Returns a value that is equal to the lowest value appearing in the input sequence.

minutes-from-dateTime ($arg as xs:dateTime?) as xs:integer? external

Returns the minute component of an xs:dateTime .

minutes-from-duration ($arg as xs:duration?) as xs:integer? external

Returns the number of minutes in a duration.

minutes-from-time ($arg as xs:time?) as xs:integer? external

Returns the minutes component of an xs:time .

month-from-date ($arg as xs:date?) as xs:integer? external

Returns the month component of an xs:date .

months-from-duration ($arg as xs:duration?) as xs:integer? external

Returns the number of months in a duration.

name () as xs:string external

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 .

name ($arg as node()?) as xs:string external

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 .

namespace-uri-for-prefix ($prefix as xs:string?, $element as element(*)) as xs:anyURI? external

Returns the namespace URI of one of the in-scope namespaces for $element , identified by its namespace prefix.

namespace-uri-from-QName ($arg as xs:QName?) as xs:anyURI? external

Returns the namespace URI part of the supplied QName.

namespace-uri () as xs:anyURI external

Returns the namespace URI part of the name of $arg , as an xs:anyURI value.

namespace-uri ($arg as node()?) as xs:anyURI external

Returns the namespace URI part of the name of $arg , as an xs:anyURI value.

nilled () as xs:boolean external

Returns true for an element that is nilled .

nilled ($arg as node()?) as xs:boolean? external

Returns true for an element that is nilled .

node-name () as xs:QName? external

Returns the name of a node, as an xs:QName .

node-name ($arg as node()?) as xs:QName? external

Returns the name of a node, as an xs:QName .

normalize-space () as xs:string external

Returns the value of $arg with leading and trailing whitespace removed, and sequences of internal whitespace reduced to a single space character.

normalize-space ($arg as xs:string?) as xs:string external

Returns the value of $arg with leading and trailing whitespace removed, and sequences of internal whitespace reduced to a single space character.

normalize-unicode ($arg as xs:string?) as xs:string external

Returns the value of $arg after applying Unicode normalization.

normalize-unicode ($arg as xs:string?, $normalizationForm as xs:string) as xs:string external

Returns the value of $arg after applying Unicode normalization.

not ($arg as item()*) as xs:boolean external

Returns true if the effective boolean value of $arg is false , or false if it is true .

number () as xs:double external

Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double .

number ($arg as xs:anyAtomicType?) as xs:double external

Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double .

one-or-more ($arg as item()*) as item()+ external

Returns $arg if it contains one or more items.

outermost ($nodes as node()*) as node()* external

Returns every node within the input sequence that has no ancestor that is itself a member of the input sequence; the nodes are returned in document order with duplicates eliminated.

parse-xml-fragment ($arg as xs:string?) as document(element(*,xs:untyped)) external

This function takes as input an XML external entity represented as a string, and returns the document node at the root of an XDM tree representing the parsed document fragment.

parse-xml ($arg as xs:string?) as document(element(*,xs:untyped)) external

This function takes as input an XML document represented as a string, and returns the document node at the root of an XDM tree representing the parsed document.

parse-xml ($arg as xs:string?, $baseURI as xs:string) as document(element(*,xs:untyped)) external

This function takes as input an XML document represented as a string, and returns the document node at the root of an XDM tree representing the parsed document.

position () as xs:integer external

Returns the context position from the dynamic context.

prefix-from-QName ($arg as xs:QName?) as xs:NCName? external

Returns the prefix component of the supplied QName.

remove ($target as item()*, $position as xs:integer) as item()* external

Returns a new sequence containing all the items of $target except the item at position $position .

replace ($input as xs:string?, $pattern as xs:string, $replacement as xs:string) as xs:string external

Returns a string produced from the input string by replacing any substrings that match a given regular expression with a supplied replacement string.

replace ($input as xs:string?, $pattern as xs:string, $replacement as xs:string, $flags as xs:string) as xs:string external

Returns a string produced from the input string by replacing any substrings that match a given regular expression with a supplied replacement string.

resolve-QName ($qname as xs:string?, $element as element(*)) as xs:QName? external

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.

resolve-uri ($relative as xs:string?) as xs:anyURI? external

Resolves a relative IRI reference against an absolute IRI.

resolve-uri ($relative as xs:string?, $base as xs:string) as xs:anyURI? external

Resolves a relative IRI reference against an absolute IRI.

reverse ($arg as item()*) as item()* external

Reverses the order of items in a sequence.

root () as node() external

Returns the root of the tree to which $arg belongs.

root ($arg as node()?) as node()? external

Returns the root of the tree to which $arg belongs.

round-half-to-even ($arg as numeric?) as numeric? external

Rounds a value to a specified number of decimal places, rounding to make the last digit even if two such values are equally near.

round-half-to-even ($arg as numeric?, $precision as xs:integer) as numeric? external

Rounds a value to a specified number of decimal places, rounding to make the last digit even if two such values are equally near.

round ($arg as numeric?) as numeric? external

Rounds a value to a specified number of decimal places, rounding upwards if two such values are equally near.

round ($arg as numeric?, $precision as xs:integer) as numeric? external

Rounds a value to a specified number of decimal places, rounding upwards if two such values are equally near.

seconds-from-dateTime ($arg as xs:dateTime?) as xs:decimal? external

Returns the seconds component of an xs:dateTime .

seconds-from-duration ($arg as xs:duration?) as xs:decimal? external

Returns the number of seconds in a duration.

seconds-from-time ($arg as xs:time?) as xs:decimal? external

Returns the seconds component of an xs:time .

serialize ($arg as item()*) as xs:string external

This function serializes the supplied input sequence $arg as described in , returning the serialized representation of the sequence as a string.

serialize ($arg as item()*, $params as element(output:serialization-parameters)?) as xs:string external

This function serializes the supplied input sequence $arg as described in , returning the serialized representation of the sequence as a string.

starts-with ($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a leading substring, taking collations into account.

starts-with ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a leading substring, taking collations into account.

static-base-uri () as xs:anyURI? external

This function returns the value of the Static Base URI property from the static context.

string-join ($arg1 as xs:string*) as xs:string external

Returns a string created by concatenating the items in a sequence, with a defined separator between adjacent items.

string-join ($arg1 as xs:string*, $arg2 as xs:string) as xs:string external

Returns a string created by concatenating the items in a sequence, with a defined separator between adjacent items.

string-length () as xs:integer external

Returns the number of characters in a string.

string-length ($arg as xs:string?) as xs:integer external

Returns the number of characters in a string.

string-to-codepoints ($arg as xs:string?) as xs:integer* external

Returns the sequence of codepoints that constitute an xs:string value.

string-to-codepoints ($arg as xs:string?) as xs:integer* external

Returns the sequence of codepoints that constitute an xs:string value.

string () as xs:string external

Returns the value of $arg represented as an xs:string .

string ($arg as item()?) as xs:string external

Returns the value of $arg represented as an xs:string .

subsequence ($sourceSeq as item()*, $startingLoc as xs:double) as item()* external

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 .

subsequence ($sourceSeq as item()*, $startingLoc as xs:double, $length as xs:double) as item()* external

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 .

substring-after ($arg1 as xs:string?, $arg2 as xs:string?) as xs:string external

Returns the part of $arg1 that follows the first occurrence of $arg2 , taking collations into account.

substring-after ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string external

Returns the part of $arg1 that follows the first occurrence of $arg2 , taking collations into account.

substring-before ($arg1 as xs:string?, $arg2 as xs:string?) as xs:string external

Returns the part of $arg1 that precedes the first occurrence of $arg2 , taking collations into account.

substring-before ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string external

Returns the part of $arg1 that precedes the first occurrence of $arg2 , taking collations into account.

substring ($sourceString as xs:string?, $start as xs:double) as xs:string external

Returns the portion of the value of $sourceString beginning at the position indicated by the value of $start and continuing for the number of characters indicated by the value of $length .

substring ($sourceString as xs:string?, $start as xs:double, $length as xs:double) as xs:string external

Returns the portion of the value of $sourceString beginning at the position indicated by the value of $start and continuing for the number of characters indicated by the value of $length .

sum ($arg as xs:anyAtomicType*) as xs:anyAtomicType external

Returns a value obtained by adding together the values in $arg .

sum ($arg as xs:anyAtomicType*, $zero as xs:anyAtomicType?) as xs:anyAtomicType? external

Returns a value obtained by adding together the values in $arg .

tail ($arg as item()*) as item()* external

Returns all but the first item in a sequence.

timezone-from-date ($arg as xs:date?) as xs:dayTimeDuration? external

Returns the timezone component of an xs:date .

timezone-from-dateTime ($arg as xs:dateTime?) as xs:dayTimeDuration? external

Returns the timezone component of an xs:dateTime .

timezone-from-time ($arg as xs:time?) as xs:dayTimeDuration? external

Returns the timezone component of an xs:time .

tokenize ($input as xs:string?, $pattern as xs:string) as xs:string* external

Returns a sequence of strings constructed by splitting the input wherever a separator is found; the separator is any substring that matches a given regular expression.

tokenize ($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:string* external

Returns a sequence of strings constructed by splitting the input wherever a separator is found; the separator is any substring that matches a given regular expression.

trace ($value as item()*, $label as xs:string) as item()* external

Provides an execution trace intended to be used in debugging queries.

translate ($arg as xs:string?, $mapString as xs:string, $transString as xs:string) as xs:string external

Returns the value of $arg modified by replacing or removing individual characters.

true () as xs:boolean external

Returns the xs:boolean value true .

unordered ($sourceSeq as item()*) as item()* external

Returns the items of $sourceSeq in an order.

unparsed-text-available ($href as xs:string?) as xs:boolean external

Because errors in evaluating the fn:unparsed-text function are non-recoverable, these two functions are provided to allow an application to determine whether a call with particular arguments would succeed.

unparsed-text-available ($href as xs:string?) as xs:boolean external

Because errors in evaluating the fn:unparsed-text function are non-recoverable, these two functions are provided to allow an application to determine whether a call with particular arguments would succeed.

unparsed-text-available ($href as xs:string?, $encoding as xs:string) as xs:boolean external

Because errors in evaluating the fn:unparsed-text function are non-recoverable, these two functions are provided to allow an application to determine whether a call with particular arguments would succeed.

unparsed-text-available ($href as xs:string?, $encoding as xs:string) as xs:boolean external

Because errors in evaluating the fn:unparsed-text function are non-recoverable, these two functions are provided to allow an application to determine whether a call with particular arguments would succeed.

unparsed-text-lines ($href as xs:string?) as xs:string* external

The fn:unparsed-text-lines function reads an external resource (for example, a file) and returns its contents as a sequence of strings, one for each line of text in the string representation of the resource.

unparsed-text-lines ($href as xs:string?, $encoding as xs:string) as xs:string* external

The fn:unparsed-text-lines function reads an external resource (for example, a file) and returns its contents as a sequence of strings, one for each line of text in the string representation of the resource.

unparsed-text-lines ($href as xs:string?, $encoding as xs:string) as xs:string* external

The fn:unparsed-text-lines function reads an external resource (for example, a file) and returns its contents as a sequence of strings, one for each line of text in the string representation of the resource.

unparsed-text ($href as xs:string?) as xs:string? external

The fn:unparsed-text function reads an external resource (for example, a file) and returns a string representation of the resource .

unparsed-text ($href as xs:string?) as xs:string? external

The fn:unparsed-text function reads an external resource (for example, a file) and returns a string representation of the resource .

unparsed-text ($href as xs:string?, $encoding as xs:string) as xs:string? external

The fn:unparsed-text function reads an external resource (for example, a file) and returns a string representation of the resource .

unparsed-text ($href as xs:string?, $encoding as xs:string) as xs:string? external

The fn:unparsed-text function reads an external resource (for example, a file) and returns a string representation of the resource .

upper-case ($arg as xs:string?) as xs:string external

Converts a string to upper case.

uri-collection () as xs:anyURI* external

Returns a sequence of xs:anyURI values representing the URIs in a resource collection.

uri-collection () as xs:anyURI* external

Returns a sequence of xs:anyURI values representing the URIs in a resource collection.

uri-collection ($arg as xs:string?) as xs:anyURI* external

Returns a sequence of xs:anyURI values representing the URIs in a resource collection.

uri-collection ($arg as xs:string?) as xs:anyURI* external

Returns a sequence of xs:anyURI values representing the URIs in a resource collection.

year-from-date ($arg as xs:date?) as xs:integer? external

Returns the year component of an xs:date .

years-from-duration ($arg as xs:duration?) as xs:integer? external

Returns the number of years in a duration.

zero-or-one ($arg as item()*) as item()? external

Returns $arg if it contains zero or one items.

Functions

QName#2

declare  function fn:QName($paramURI as xs:string?, $paramQName as xs:string) as xs:QName external

Constructs an xs:QName value given a namespace URI and a lexical QName.

This function is deterministic, context-independent, and focus-independent.

The namespace URI in the returned QName is taken from $paramURI. If $paramURI is the zero-length string or the empty sequence, it represents "no namespace".

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.

A dynamic error is raised if $paramQName does not have the correct lexical form for an instance of xs:QName.

A dynamic error is raised if $paramURI is the zero-length string or the empty sequence, and the value of $paramQName contains a colon (:).

A dynamic error may be raised if $paramURI is not a valid URI (XML Namespaces 1.0) or IRI (XML Namespaces 1.1).

Parameters

paramURI as xs:string
paramQName as xs:string

Returns

xs:QName

abs#1

declare  function fn:abs($arg as numeric?) as numeric? external

Returns the absolute value of $arg.

This function is deterministic, context-independent, and focus-independent.

General rules: see .

If $arg is negative the function returns -$arg, otherwise it returns $arg.

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.

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 [Formal Semantics].

The expression fn:abs(10.5) returns 10.5.

The expression fn:abs(-10.5) returns 10.5.

Parameters

arg as numeric

Returns

numeric?

adjust-date-to-timezone#1

declare  function fn:adjust-date-to-timezone($arg as xs:date?) as xs:date? external

Adjusts an xs:date value to a specific timezone, or to no timezone at all; the result is the date in the target timezone that contains the starting instant of the supplied date.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

If $timezone is not specified, then the effective value of $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the function returns the empty sequence.

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 local value of $arg without its timezone component.

If $arg has a timezone component and $timezone is not the empty sequence, then the function returns the value of the expression:

Let $dt be the value of fn:dateTime($arg, xs:time('00:00:00')).

Let $adt be the value of fn:adjust-dateTime-to-timezone($dt, $timezone)

The function returns the value of xs:date($adt)

A dynamic error is raised if $timezone is less than -PT14H or greater than PT14H or is not an integral number of minutes.

Parameters

arg as xs:date

Returns

xs:date?

adjust-date-to-timezone#2

declare  function fn:adjust-date-to-timezone($arg as xs:date?, $timezone as xs:dayTimeDuration?) as xs:date? external

Adjusts an xs:date value to a specific timezone, or to no timezone at all; the result is the date in the target timezone that contains the starting instant of the supplied date.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

If $timezone is not specified, then the effective value of $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the function returns the empty sequence.

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 local value of $arg without its timezone component.

If $arg has a timezone component and $timezone is not the empty sequence, then the function returns the value of the expression:

Let $dt be the value of fn:dateTime($arg, xs:time('00:00:00')).

Let $adt be the value of fn:adjust-dateTime-to-timezone($dt, $timezone)

The function returns the value of xs:date($adt)

A dynamic error is raised if $timezone is less than -PT14H or greater than PT14H or is not an integral number of minutes.

Parameters

arg as xs:date
timezone as xs:dayTimeDuration

Returns

xs:date?

adjust-dateTime-to-timezone#1

declare  function fn:adjust-dateTime-to-timezone($arg as xs:dateTime?) as xs:dateTime external

Adjusts an xs:dateTime value to a specific timezone, or to no timezone at all.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

If $timezone is not specified, then the effective value of $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the function returns the empty sequence.

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 local value of $arg without its timezone component.

If $arg has a timezone component and $timezone is not the empty sequence, then the result is the xs:dateTime value that is equal to $arg and that has a timezone component equal to $timezone.

A dynamic error is raised if $timezone is less than -PT14H or greater than PT14H or is not an integral number of minutes.

Parameters

arg as xs:dateTime

Returns

xs:dateTime

adjust-dateTime-to-timezone#2

declare  function fn:adjust-dateTime-to-timezone($arg as xs:dateTime?, $timezone as xs:dayTimeDuration?) as xs:dateTime external

Adjusts an xs:dateTime value to a specific timezone, or to no timezone at all.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

If $timezone is not specified, then the effective value of $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the function returns the empty sequence.

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 local value of $arg without its timezone component.

If $arg has a timezone component and $timezone is not the empty sequence, then the result is the xs:dateTime value that is equal to $arg and that has a timezone component equal to $timezone.

A dynamic error is raised if $timezone is less than -PT14H or greater than PT14H or is not an integral number of minutes.

Parameters

arg as xs:dateTime
timezone as xs:dayTimeDuration

Returns

xs:dateTime

adjust-time-to-timezone#1

declare  function fn:adjust-time-to-timezone($arg as xs:time?) as xs:time? external

Adjusts an xs:time value to a specific timezone, or to no timezone at all.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

If $timezone is not specified, then the effective value of $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the function returns the empty sequence.

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 $dt be the xs:dateTime value fn:dateTime(xs:date('1972-12-31'), $arg).

Let $adt be the value of fn:adjust-dateTime-to-timezone($dt, $timezone)

The function returns the xs:time value xs:time($adt).

A dynamic error is raised if $timezone is less than -PT14H or greater than PT14H or if does not contain an integral number of minutes.

Parameters

arg as xs:time

Returns

xs:time?

adjust-time-to-timezone#2

declare  function fn:adjust-time-to-timezone($arg as xs:time?, $timezone as xs:dayTimeDuration?) as xs:time? external

Adjusts an xs:time value to a specific timezone, or to no timezone at all.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

If $timezone is not specified, then the effective value of $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the function returns the empty sequence.

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 $dt be the xs:dateTime value fn:dateTime(xs:date('1972-12-31'), $arg).

Let $adt be the value of fn:adjust-dateTime-to-timezone($dt, $timezone)

The function returns the xs:time value xs:time($adt).

A dynamic error is raised if $timezone is less than -PT14H or greater than PT14H or if does not contain an integral number of minutes.

Parameters

arg as xs:time
timezone as xs:dayTimeDuration

Returns

xs:time?

analyze-string#2

declare  function fn:analyze-string($input as xs:string?, $pattern as xs:string) as element(fn:analyze-string-result) external

Analyzes a string using a regular expression, returning an XML structure that identifies which parts of the input string matched or failed to match the regular expression, and in the case of matched substrings, which substrings matched each capturing group in the regular expression.

This function is nondeterministic, context-independent, and focus-independent.

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 .

The $flags argument is interpreted in the same way as for the fn:matches function.

If $input is the empty sequence the function behaves as if $input were the zero-length string. In this situation the result will be an element node with no children.

The function returns an element node whose local name is analyze-string-result. This element and all its descendant elements have the namespace URI http://www.w3.org/2005/xpath-functions. The namespace prefix is . The children of this element are a sequence of fn:match and fn:non-match elements. This sequence is formed by breaking the $input string into a sequence of strings, returning any substring that matches $pattern as the content of a match element, and any intervening substring as the content of a non-match element.

More specifically, the function starts at the beginning of the input string and attempts to find the first substring that matches the regular expression. If there are several matches, the first match is defined to be the one whose starting position comes first in the string. If several alternatives within the regular expression both match at the same position in the input string, then the match that is chosen is the first alternative that matches. For example, if the input string is The quick brown fox jumps and the regular expression is jump|jumps, then the match that is chosen is jump.

Having found the first match, the instruction proceeds to find the second and subsequent matches by repeating the search, starting at the first character that was not included in the previous match.

The input string is thus partitioned into a sequence of substrings, some of which match the regular expression, others which do not match it. Each substring will contain at least one character. This sequence is represented in the result by the sequence of fn:match and fn:non-match children of the returned element node; the string value of the fn:match or fn:non-match element will be the corresponding substring of $input, and the string value of the returned element node will therefore be the same as $input.

The content of an fn:non-match element is always a single text node.

The content of a fn:match element, however, is in general a sequence of text nodes and fn:group element children. An fn:group element with a nr attribute having the integer value N identifies the substring captured by the Nth parenthesized sub-expression in the regular expression. For each capturing subexpression there will be at most one corresponding fn:group element in each fn:match element in the result.

If the function is called twice with the same arguments, it is whether the two calls return the same element node or distinct (but deep equal) element nodes. In this respect it is nondeterministic.

The base URI of the element nodes in the result is

A schema is defined for the structure of the returned element, containing the definitions below. The returned element and its descendants will have type annotations obtained by validating the returned element against this schema, unless the function is used in an environment where type annotations are not supported (for example, a Basic XSLT Processor), in which case the elements will all be annotated as xs:untyped and the attributes as xs:untypedAtomic.

A free-standing copy of this schema can be found at analyze-string.xsd

<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2005/xpath-functions" xmlns:fn="http://www.w3.org/2005/xpath-functions" elementFormDefault="qualified"> <xs:element name="analyze-string-result" type="fn:analyze-string-result-type"/> <xs:element name="match" type="fn:match-type"/> <xs:element name="non-match" type="xs:string"/> <xs:element name="group" type="fn:group-type"/> <xs:complexType name="analyze-string-result-type" mixed="true"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="fn:match"/> <xs:element ref="fn:non-match"/> </xs:choice> </xs:complexType> <xs:complexType name="match-type" mixed="true"> <xs:sequence> <xs:element ref="fn:group" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="group-type" mixed="true"> <xs:sequence> <xs:element ref="fn:group" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="nr" type="xs:positiveInteger"/> </xs:complexType> </xs:schema>

A dynamic error is raised if the value of $pattern is invalid according to the rules described in section .

A dynamic error is raised if the value of $flags is invalid according to the rules described in section .

A dynamic error is raised if the supplied $pattern matches a zero-length string, that is, if fn:matches("", $pattern, $flags) returns true.

Parameters

input as xs:string
pattern as xs:string

Returns

element(fn:analyze-string-result)

analyze-string#3

declare  function fn:analyze-string($input as xs:string?, $pattern as xs:string, $flags as xs:string) as element(fn:analyze-string-result) external

Analyzes a string using a regular expression, returning an XML structure that identifies which parts of the input string matched or failed to match the regular expression, and in the case of matched substrings, which substrings matched each capturing group in the regular expression.

This function is nondeterministic, context-independent, and focus-independent.

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 .

The $flags argument is interpreted in the same way as for the fn:matches function.

If $input is the empty sequence the function behaves as if $input were the zero-length string. In this situation the result will be an element node with no children.

The function returns an element node whose local name is analyze-string-result. This element and all its descendant elements have the namespace URI http://www.w3.org/2005/xpath-functions. The namespace prefix is . The children of this element are a sequence of fn:match and fn:non-match elements. This sequence is formed by breaking the $input string into a sequence of strings, returning any substring that matches $pattern as the content of a match element, and any intervening substring as the content of a non-match element.

More specifically, the function starts at the beginning of the input string and attempts to find the first substring that matches the regular expression. If there are several matches, the first match is defined to be the one whose starting position comes first in the string. If several alternatives within the regular expression both match at the same position in the input string, then the match that is chosen is the first alternative that matches. For example, if the input string is The quick brown fox jumps and the regular expression is jump|jumps, then the match that is chosen is jump.

Having found the first match, the instruction proceeds to find the second and subsequent matches by repeating the search, starting at the first character that was not included in the previous match.

The input string is thus partitioned into a sequence of substrings, some of which match the regular expression, others which do not match it. Each substring will contain at least one character. This sequence is represented in the result by the sequence of fn:match and fn:non-match children of the returned element node; the string value of the fn:match or fn:non-match element will be the corresponding substring of $input, and the string value of the returned element node will therefore be the same as $input.

The content of an fn:non-match element is always a single text node.

The content of a fn:match element, however, is in general a sequence of text nodes and fn:group element children. An fn:group element with a nr attribute having the integer value N identifies the substring captured by the Nth parenthesized sub-expression in the regular expression. For each capturing subexpression there will be at most one corresponding fn:group element in each fn:match element in the result.

If the function is called twice with the same arguments, it is whether the two calls return the same element node or distinct (but deep equal) element nodes. In this respect it is nondeterministic.

The base URI of the element nodes in the result is

A schema is defined for the structure of the returned element, containing the definitions below. The returned element and its descendants will have type annotations obtained by validating the returned element against this schema, unless the function is used in an environment where type annotations are not supported (for example, a Basic XSLT Processor), in which case the elements will all be annotated as xs:untyped and the attributes as xs:untypedAtomic.

A free-standing copy of this schema can be found at analyze-string.xsd

<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2005/xpath-functions" xmlns:fn="http://www.w3.org/2005/xpath-functions" elementFormDefault="qualified"> <xs:element name="analyze-string-result" type="fn:analyze-string-result-type"/> <xs:element name="match" type="fn:match-type"/> <xs:element name="non-match" type="xs:string"/> <xs:element name="group" type="fn:group-type"/> <xs:complexType name="analyze-string-result-type" mixed="true"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="fn:match"/> <xs:element ref="fn:non-match"/> </xs:choice> </xs:complexType> <xs:complexType name="match-type" mixed="true"> <xs:sequence> <xs:element ref="fn:group" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="group-type" mixed="true"> <xs:sequence> <xs:element ref="fn:group" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="nr" type="xs:positiveInteger"/> </xs:complexType> </xs:schema>

A dynamic error is raised if the value of $pattern is invalid according to the rules described in section .

A dynamic error is raised if the value of $flags is invalid according to the rules described in section .

A dynamic error is raised if the supplied $pattern matches a zero-length string, that is, if fn:matches("", $pattern, $flags) returns true.

Parameters

input as xs:string
pattern as xs:string
flags as xs:string

Returns

element(fn:analyze-string-result)

available-environment-variables#0

declare  function fn:available-environment-variables() as xs:string* external

Returns a list of environment variable names that are suitable for passing to fn:environment-variable, as a (possibly empty) sequence of strings.

This function is deterministic, context-dependent, and focus-independent. It depends on environment variables.

The function returns a sequence of strings, being the names of the environment variables in the dynamic context in some implementation-dependent order.

The function is deterministic: that is, the set of available environment variables does not vary during evaluation.

The function returns a list of strings, containing no duplicates.

It is intended that the strings in this list should be suitable for passing to fn:environment-variable.

See also the note on security under the definition of the fn:environment-variable function. If access to environment variables has been disabled, fn:available-environment-variables always returns the empty sequence.

Parameters

Returns

xs:string*

available-environment-variables#0

declare  function fn:available-environment-variables() as xs:string* external

Returns a list of environment variable names that are suitable for passing to fn:environment-variable, as a (possibly empty) sequence of strings.

This function is deterministic, context-dependent, and focus-independent. It depends on environment variables.

The function returns a sequence of strings, being the names of the environment variables in the dynamic context in some implementation-dependent order.

The function is deterministic: that is, the set of available environment variables does not vary during evaluation.

The function returns a list of strings, containing no duplicates.

It is intended that the strings in this list should be suitable for passing to fn:environment-variable.

See also the note on security under the definition of the fn:environment-variable function. If access to environment variables has been disabled, fn:available-environment-variables always returns the empty sequence.

Parameters

Returns

xs:string*

avg#1

declare  function fn:avg($arg as xs:anyAtomicType*) as xs:anyAtomicType? external

Returns the average of the values in the input sequence $arg, that is, the sum of the values divided by the number of values.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the empty sequence is returned.

If $arg contains values of type xs:untypedAtomic they are cast to xs:double.

Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values. For numeric values, the numeric promotion rules defined in are used to promote all values to a single common type. After these operations, $arg must contain items of a single type, which must be one of the four numeric types, xs:yearMonthDuration or xs:dayTimeDuration or one if its subtypes.

The function returns the average of the values as sum($arg) div count($arg); but the implementation may use an otherwise equivalent algorithm that avoids arithmetic overflow.

For detailed type semantics, see [Formal Semantics].

A type error is raised if the input sequence contains items of incompatible types, as described above.

Parameters

arg as xs:anyAtomicType

Returns

xs:anyAtomicType?

base-uri#0

declare  function fn:base-uri() as xs:anyURI? external

Returns the base URI of a node.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

The zero-argument version of the function returns the base URI of the context node: it is equivalent to calling fn:base-uri(.).

The single-argument version of the function behaves as follows:

If $arg is the empty sequence, the function returns the empty sequence.Otherwise, the function returns the value of the dm:base-uri accessor applied to the node $arg. This accessor is defined, for each kind of node, in the XDM specification (See ).As explained in XDM, document, element and processing-instruction nodes have a base-uri property which may be empty. The base-uri property for all other node kinds is the empty sequence. The dm:base-uri accessor returns the base-uri property of a node if it exists and is non-empty; otherwise it returns the result of applying the dm:base-uri accessor to its parent, recursively. If the node does not have a parent, or if the recursive ascent up the ancestor chain encounters a parentless node whose base-uri property is empty, the empty sequence is returned. In the case of namespace nodes, however, the result is always an empty sequence -- it does not depend on the base URI of the parent element.

See also fn:static-base-uri.

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:anyURI?

base-uri#1

declare  function fn:base-uri($arg as node()?) as xs:anyURI? external

Returns the base URI of a node.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

The zero-argument version of the function returns the base URI of the context node: it is equivalent to calling fn:base-uri(.).

The single-argument version of the function behaves as follows:

If $arg is the empty sequence, the function returns the empty sequence.Otherwise, the function returns the value of the dm:base-uri accessor applied to the node $arg. This accessor is defined, for each kind of node, in the XDM specification (See ).As explained in XDM, document, element and processing-instruction nodes have a base-uri property which may be empty. The base-uri property for all other node kinds is the empty sequence. The dm:base-uri accessor returns the base-uri property of a node if it exists and is non-empty; otherwise it returns the result of applying the dm:base-uri accessor to its parent, recursively. If the node does not have a parent, or if the recursive ascent up the ancestor chain encounters a parentless node whose base-uri property is empty, the empty sequence is returned. In the case of namespace nodes, however, the result is always an empty sequence -- it does not depend on the base URI of the parent element.

See also fn:static-base-uri.

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

xs:anyURI?

boolean#1

declare  function fn:boolean($arg as item()*) as xs:boolean external

Computes the effective boolean value of the sequence $arg.

The function computes the effective boolean value of a sequence, defined according to the following rules. See also .

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 .

The static semantics of this function are described in [Formal Semantics].

The result of this function is not necessarily the same as $arg cast as xs:boolean. For example, fn:boolean("false") returns the value true whereas "false" cast as xs:boolean (which can also be written xs:boolean("false")) returns false.

let $abc := ("a", "b", "")

fn:boolean($abc) raises a type error .

The expression fn:boolean($abc[1]) returns true().

The expression fn:boolean($abc[0]) returns false().

The expression fn:boolean($abc[3]) returns false().

Parameters

arg as item()

Returns

xs:boolean

ceiling#1

declare  function fn:ceiling($arg as numeric?) as numeric? external

Rounds $arg upwards to a whole number.

This function is deterministic, context-independent, and focus-independent.

General rules: see .

The function returns the smallest (closest to negative infinity) number with no fractional part that is not less than the value of $arg.

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.

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.

For detailed type semantics, see [Formal Semantics].

The expression fn:ceiling(10.5) returns 11.

The expression fn:ceiling(-10.5) returns -10.

Parameters

arg as numeric

Returns

numeric?

codepoint-equal#2

declare  function fn:codepoint-equal($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:boolean? external

Returns true if two strings are equal, considered codepoint-by-codepoint.

This function is deterministic, context-independent, and focus-independent.

If either argument is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns true or false depending on whether the value of $comparand1 is equal to the value of $comparand2, according to the Unicode codepoint collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

This function allows xs:anyURI values to be compared without having to specify the Unicode codepoint collation.

Parameters

comparand1 as xs:string
comparand2 as xs:string

Returns

xs:boolean?

codepoints-to-string#1

declare  function fn:codepoints-to-string($arg as xs:integer*) as xs:string external

Creates an xs:string from a sequence of codepoints.

This function is deterministic, context-independent, and focus-independent.

The function returns the string made up from the characters whose Unicode codepoints are supplied in $arg. This will be the zero-length string if $arg is the empty sequence.

A dynamic error is raised if any of the codepoints in $arg is not a permitted XML character.

Parameters

arg as xs:integer

Returns

xs:string

codepoints-to-string#1

declare  function fn:codepoints-to-string($arg as xs:integer*) as xs:string external

Creates an xs:string from a sequence of codepoints.

This function is deterministic, context-independent, and focus-independent.

The function returns the string made up from the characters whose Unicode codepoints are supplied in $arg. This will be the zero-length string if $arg is the empty sequence.

A dynamic error is raised if any of the codepoints in $arg is not a permitted XML character.

Parameters

arg as xs:integer

Returns

xs:string

collection#0

declare  function fn:collection() as node()* external

Returns a sequence of nodes representing a collection of documents indentified by a collection URI; or a default collection if no URI is supplied.

This function is deterministic, context-dependent, and focus-independent. It depends on available node collections, and static base uri.

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 node collections described in .

If Available node collections provides a mapping from this string to a sequence of nodes, the function returns that sequence. If Available node collections maps the string to an empty sequence, then the function returns an empty sequence.

If $arg is not specified, the function returns the sequence of the nodes in the default node collection in the dynamic context. See .

If the value of $arg is a relative xs:anyURI, it is resolved against the value of the base-URI property from the static context.

If $arg is the empty sequence, the function behaves as if it had been called without an argument. See above.

By default, this function is deterministic. This means that repeated calls on the function with the same argument will return the same result. However, for performance reasons, implementations may provide a user option to evaluate the function without a guarantee of determinism. The manner in which any such option is provided is . If the user has not selected such an option, a call to this function must either return a deterministic result or must raise a dynamic error .

There is no requirement that the returned nodes should be in document order, nor is there a requirement that the result should contain no duplicates.

For detailed type semantics, see [Formal Semantics].

A dynamic error is raised if no URI is supplied and the value of the default collection is absent.

A dynamic error is raised if available node collections provides no mapping for the absolutized URI.

A dynamic error is raised if $arg is not a valid xs:anyURI.

Parameters

Returns

node()*

collection#1

declare  function fn:collection($arg as xs:string?) as node()* external

Returns a sequence of nodes representing a collection of documents indentified by a collection URI; or a default collection if no URI is supplied.

This function is deterministic, context-dependent, and focus-independent. It depends on available node collections, and static base uri.

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 node collections described in .

If Available node collections provides a mapping from this string to a sequence of nodes, the function returns that sequence. If Available node collections maps the string to an empty sequence, then the function returns an empty sequence.

If $arg is not specified, the function returns the sequence of the nodes in the default node collection in the dynamic context. See .

If the value of $arg is a relative xs:anyURI, it is resolved against the value of the base-URI property from the static context.

If $arg is the empty sequence, the function behaves as if it had been called without an argument. See above.

By default, this function is deterministic. This means that repeated calls on the function with the same argument will return the same result. However, for performance reasons, implementations may provide a user option to evaluate the function without a guarantee of determinism. The manner in which any such option is provided is . If the user has not selected such an option, a call to this function must either return a deterministic result or must raise a dynamic error .

There is no requirement that the returned nodes should be in document order, nor is there a requirement that the result should contain no duplicates.

For detailed type semantics, see [Formal Semantics].

A dynamic error is raised if no URI is supplied and the value of the default collection is absent.

A dynamic error is raised if available node collections provides no mapping for the absolutized URI.

A dynamic error is raised if $arg is not a valid xs:anyURI.

Parameters

arg as xs:string

Returns

node()*

compare#2

declare  function fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer? external

Returns -1, 0, or 1, depending on whether $comparand1 collates before, equal to, or after $comparand2 according to the rules of a selected collation.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

If either $comparand1 or $comparand2 is the empty sequence, the function returns the empty sequence.

This function, called with the first signature, defines the semantics of the "eq", "ne", "gt", "lt", "le" and "ge" operators on xs:string values.

The expression fn:compare('abc', 'abc') returns 0.

The expression fn:compare('Strasse', 'Straße') returns 0. (Assuming the default collation includes provisions that equate ss and the (German) character ß (sharp-s). Otherwise, the returned value depends on the semantics of the default collation.).

The expression fn:compare('Strasse', 'Straße', 'http://example.com/deutsch') returns 0. (Assuming the collation identified by the URI http://example.com/deutsch includes provisions that equate ss and the (German) character ß (sharp-s). Otherwise, the returned value depends on the semantics of that collation.).

The expression fn:compare('Strassen', 'Straße') returns 1. (Assuming the default collation includes provisions that treat differences between ss and the (German) character ß (sharp-s) with less strength than the differences between the base characters, such as the final n. ).

Parameters

comparand1 as xs:string
comparand2 as xs:string

Returns

xs:integer?

compare#3

declare  function fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer? external

Returns -1, 0, or 1, depending on whether $comparand1 collates before, equal to, or after $comparand2 according to the rules of a selected collation.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

If either $comparand1 or $comparand2 is the empty sequence, the function returns the empty sequence.

This function, called with the first signature, defines the semantics of the "eq", "ne", "gt", "lt", "le" and "ge" operators on xs:string values.

The expression fn:compare('abc', 'abc') returns 0.

The expression fn:compare('Strasse', 'Straße') returns 0. (Assuming the default collation includes provisions that equate ss and the (German) character ß (sharp-s). Otherwise, the returned value depends on the semantics of the default collation.).

The expression fn:compare('Strasse', 'Straße', 'http://example.com/deutsch') returns 0. (Assuming the collation identified by the URI http://example.com/deutsch includes provisions that equate ss and the (German) character ß (sharp-s). Otherwise, the returned value depends on the semantics of that collation.).

The expression fn:compare('Strassen', 'Straße') returns 1. (Assuming the default collation includes provisions that treat differences between ss and the (German) character ß (sharp-s) with less strength than the differences between the base characters, such as the final n. ).

Parameters

comparand1 as xs:string
comparand2 as xs:string
collation as xs:string

Returns

xs:integer?

concat#2

declare  function fn:concat($arg1 as xs:anyAtomicType?, $arg2 as xs:anyAtomicType?) as xs:string external

Returns the concatenation of the string values of the arguments.

The two-argument form of this function defines the semantics of the "||" operator.

This function is deterministic, context-independent, and focus-independent.

This function accepts two or more xs:anyAtomicType arguments and casts each one to xs:string. The function returns the xs:string that is the concatenation of the values of its arguments after conversion. If any argument is the empty sequence, that 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 .

Parameters

arg1 as xs:anyAtomicType
arg2 as xs:anyAtomicType

Returns

xs:string

contains#2

declare  function fn:contains($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a substring, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Minimal match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string

Returns

xs:boolean

contains#3

declare  function fn:contains($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a substring, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Minimal match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string
collation as xs:string

Returns

xs:boolean

count#1

declare  function fn:count($arg as item()*) as xs:integer external

Returns the number of items in a sequence.

This function is deterministic, context-independent, and focus-independent.

The function returns the number of items in the value of $arg.

Returns 0 if $arg is the empty sequence.

Parameters

arg as item()

Returns

xs:integer

current-date#0

declare  function fn:current-date() as xs:date external

Returns the current date.

This function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

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 . The precise instant during the query or transformation represented by the value of fn:current-date is .

The returned date will always have an associated timezone, which will always be the same as the implicit timezone in the dynamic context

Parameters

Returns

xs:date

current-dateTime#0

declare  function fn:current-dateTime() as xs:dateTimeStamp external

Returns the current date and time (with timezone).

This function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

Returns the current dateTime (with timezone) from the dynamic context. (See .) 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 . The precise instant during the query or transformation represented by the value of fn:current-dateTime() is .

If the implementation supports data types from XSD 1.1 then the returned value will be an instance of xs:dateTimeStamp. Otherwise, the only guarantees are that it will be an instance of xs:dateTime and will have a timezone component.

The returned xs:dateTime will always have an associated timezone, which will always be the same as the implicit timezone in the dynamic context

Parameters

Returns

xs:dateTimeStamp

current-time#0

declare  function fn:current-time() as xs:time external

Returns the current time.

This function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

Returns xs:time(fn:current-dateTime()). This is an xs:time (with timezone) that is current at some time during the evaluation of a query or transformation in which fn:current-time is executed.

This function is . The precise instant during the query or transformation represented by the value of fn:current-time() is .

The returned time will always have an associated timezone, which will always be the same as the implicit timezone in the dynamic context

Parameters

Returns

xs:time

data#0

declare  function fn:data() as xs:anyAtomicType* external

Returns the result of atomizing a sequence, that is, replacing all nodes in the sequence by their typed values.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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 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 appended to the result sequence.

If the item is a node, the typed value of the node is appended to the result sequence. The typed value is a sequence of zero or more atomic values: specifically, the result of the dm:typed-value accessor as defined in (See ).

A type error is raised if an item in the sequence $arg is a node that does not have a typed value.

A type error is raised if an item in the sequence $arg is a function item.

A dynamic error is raised if $arg is omitted and the context item is absent.

Parameters

Returns

xs:anyAtomicType*

data#1

declare  function fn:data($arg as item()*) as xs:anyAtomicType* external

Returns the result of atomizing a sequence, that is, replacing all nodes in the sequence by their typed values.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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 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 appended to the result sequence.

If the item is a node, the typed value of the node is appended to the result sequence. The typed value is a sequence of zero or more atomic values: specifically, the result of the dm:typed-value accessor as defined in (See ).

A type error is raised if an item in the sequence $arg is a node that does not have a typed value.

A type error is raised if an item in the sequence $arg is a function item.

A dynamic error is raised if $arg is omitted and the context item is absent.

Parameters

arg as item()

Returns

xs:anyAtomicType*

dateTime#2

declare  function fn:dateTime($arg1 as xs:date?, $arg2 as xs:time?) as xs:dateTime? external

Returns an xs:dateTime value created by combining an xs:date and an xs:time.

This function is deterministic, context-independent, and focus-independent.

If either $arg1 or $arg2 is the empty sequence the function returns the empty sequence.

Otherwise, the function returns an xs:dateTime whose date component is equal to $arg1 and whose time component is equal to $arg2.

The timezone of the result is computed as follows:

If neither argument has a timezone, the result has no timezone.

If exactly one of the arguments has a timezone, or if both arguments have the same timezone, the result has this timezone.

A dynamic error is raised if the two arguments both have timezones and the timezones are different.

Parameters

arg1 as xs:date
arg2 as xs:time

Returns

xs:dateTime?

day-from-date#1

declare  function fn:day-from-date($arg as xs:date?) as xs:integer? external

Returns the day component of an xs:date.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.

The expression fn:day-from-date(xs:date("1999-05-31-05:00")) returns 31.

The expression fn:day-from-date(xs:date("2000-01-01+05:00")) returns 1.

Parameters

arg as xs:date

Returns

xs:integer?

days-from-duration#1

declare  function fn:days-from-duration($arg as xs:duration?) as xs:integer? external

Returns the number of days in a duration.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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 ) and then computing the days component as described in .

If $arg is a negative duration then the result will be negative..

If $arg is an xs:yearMonthDuration the function returns 0.

The expression fn:days-from-duration(xs:dayTimeDuration("P3DT10H")) returns 3.

The expression fn:days-from-duration(xs:dayTimeDuration("P3DT55H")) returns 5.

The expression fn:days-from-duration(xs:yearMonthDuration("P3Y5M")) returns 0.

Parameters

arg as xs:duration

Returns

xs:integer?

deep-equal#2

declare  function fn:deep-equal($parameter1 as item()*, $parameter2 as item()*) as xs:boolean external

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.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

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 .

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.

Call the two items $i1 and $i2 respectively.

If $i1 and $i2 are both atomic values, they are deep-equal if and only if ($i1 eq $i2) is true, or if both values are NaN. If the eq operator is not defined for $i1 and $i2, the function returns false.

If one of the pair $i1 or $i2 is an atomic value and the other is not, the function returns false.

If $i1 and $i2 are both nodes, they are compared as described below:

If the two nodes are of different kinds, the result is false.

If the two nodes are both document nodes then they are deep-equal if and only if the sequence $i1/(*|text()) is deep-equal to the sequence $i2/(*|text()).

If the two nodes are both element nodes then they are deep-equal if and only if all of the following conditions are satisfied:

The two nodes have the same name, that is (node-name($i1) eq node-name($i2)).

Either both nodes are both annotated as having simple content or both nodes are annotated as having complex content. For this purpose "simple content" means either a simple type or a complex type with simple content; "complex content" means a complex type whose variety is mixed, element-only, or empty.

It is a consequence of this rule that validating a document D against a schema will usually (but not necessarily) result in a document that is not deep-equal to D. The exception is when the schema allows all elements to have mixed content.

The two nodes have the same number of attributes, and for every attribute $a1 in $i1/@* there exists an attribute $a2 in $i2/@* such that $a1 and $a2 are deep-equal.

One of the following conditions holds:

Both element nodes are annotated as having simple content (as defined in 3(b) above), and the typed value of $i1 is deep-equal to the typed value of $i2.

Both element nodes have a type annotation that is a complex type with variety element-only, and the sequence $i1/* is deep-equal to the sequence $i2/*.

Both element nodes have a type annotation that is a complex type with variety mixed, and the sequence $i1/(*|text()) is deep-equal to the sequence $i2/(*|text()).

Both element nodes have a type annotation that is a complex type with variety empty.

If the two nodes are both attribute nodes then they are deep-equal if and only if both the following conditions are satisfied:

The two nodes have the same name, that is (node-name($i1) eq node-name($i2)).

The typed value of $i1 is deep-equal to the typed value of $i2.

If the two nodes are both processing instruction nodes or namespace bindings, then they are deep-equal if and only if both the following conditions are satisfied:

The two nodes have the same name, that is (node-name($i1) eq node-name($i2)).

The string value of $i1 is equal to the string value of $i2.

If the two nodes are both namespace nodes, then they are deep-equal if and only if both the following conditions are satisfied:

The two nodes either have the same name or are both nameless, that is fn:deep-equal(node-name($i1), node-name($i2)).

The string value of $i1 is equal to the string value of $i2 when compared using the Unicode codepoint collation.

If the two nodes are both text nodes or comment nodes, then they are deep-equal if and only if their string-values are equal.

A type error is raised if either input sequence contains a function item.

Parameters

parameter1 as item()
parameter2 as item()

Returns

xs:boolean

deep-equal#3

declare  function fn:deep-equal($parameter1 as item()*, $parameter2 as item()*, $collation as xs:string) as xs:boolean external

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.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

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 .

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.

Call the two items $i1 and $i2 respectively.

If $i1 and $i2 are both atomic values, they are deep-equal if and only if ($i1 eq $i2) is true, or if both values are NaN. If the eq operator is not defined for $i1 and $i2, the function returns false.

If one of the pair $i1 or $i2 is an atomic value and the other is not, the function returns false.

If $i1 and $i2 are both nodes, they are compared as described below:

If the two nodes are of different kinds, the result is false.

If the two nodes are both document nodes then they are deep-equal if and only if the sequence $i1/(*|text()) is deep-equal to the sequence $i2/(*|text()).

If the two nodes are both element nodes then they are deep-equal if and only if all of the following conditions are satisfied:

The two nodes have the same name, that is (node-name($i1) eq node-name($i2)).

Either both nodes are both annotated as having simple content or both nodes are annotated as having complex content. For this purpose "simple content" means either a simple type or a complex type with simple content; "complex content" means a complex type whose variety is mixed, element-only, or empty.

It is a consequence of this rule that validating a document D against a schema will usually (but not necessarily) result in a document that is not deep-equal to D. The exception is when the schema allows all elements to have mixed content.

The two nodes have the same number of attributes, and for every attribute $a1 in $i1/@* there exists an attribute $a2 in $i2/@* such that $a1 and $a2 are deep-equal.

One of the following conditions holds:

Both element nodes are annotated as having simple content (as defined in 3(b) above), and the typed value of $i1 is deep-equal to the typed value of $i2.

Both element nodes have a type annotation that is a complex type with variety element-only, and the sequence $i1/* is deep-equal to the sequence $i2/*.

Both element nodes have a type annotation that is a complex type with variety mixed, and the sequence $i1/(*|text()) is deep-equal to the sequence $i2/(*|text()).

Both element nodes have a type annotation that is a complex type with variety empty.

If the two nodes are both attribute nodes then they are deep-equal if and only if both the following conditions are satisfied:

The two nodes have the same name, that is (node-name($i1) eq node-name($i2)).

The typed value of $i1 is deep-equal to the typed value of $i2.

If the two nodes are both processing instruction nodes or namespace bindings, then they are deep-equal if and only if both the following conditions are satisfied:

The two nodes have the same name, that is (node-name($i1) eq node-name($i2)).

The string value of $i1 is equal to the string value of $i2.

If the two nodes are both namespace nodes, then they are deep-equal if and only if both the following conditions are satisfied:

The two nodes either have the same name or are both nameless, that is fn:deep-equal(node-name($i1), node-name($i2)).

The string value of $i1 is equal to the string value of $i2 when compared using the Unicode codepoint collation.

If the two nodes are both text nodes or comment nodes, then they are deep-equal if and only if their string-values are equal.

A type error is raised if either input sequence contains a function item.

Parameters

parameter1 as item()
parameter2 as item()
collation as xs:string

Returns

xs:boolean

default-collation#0

declare  function fn:default-collation() as xs:string external

Returns the value of the default collation property from the static context.

This function is deterministic, context-dependent, and focus-independent. It depends on collations.

Returns the value of the default collation property from the static context. Components of the static context are discussed in .

The default collation property can never be absent. If it is not explicitly defined, a system defined default can be invoked. If this is not provided, the Unicode codepoint collation (http://www.w3.org/2005/xpath-functions/collation/codepoint) is used.

Parameters

Returns

xs:string

distinct-values#1

declare  function fn:distinct-values($arg as xs:anyAtomicType*) as xs:anyAtomicType* external

Returns the values that appear in a sequence, with duplicates eliminated.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

The function returns the sequence that results from removing from $arg all but one of a set of values that are equal to one another. Values are compared using the eq operator, subject to the caveats defined below.

Values of type xs:untypedAtomic are compared as if they were of type xs:string.

Values that cannot be compared, because the eq operator is not defined for their types, are considered to be distinct.

The collation used by this function is determined according to the rules in . This collation is used when string comparison is required.

For xs:float and xs:double values, positive zero is equal to negative zero and, although NaN does not equal itself, if $arg contains multiple NaN values a single NaN is returned.

If xs:dateTime, xs:date or xs:time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for the purpose of comparison. Note that xs:dateTime, xs:date or xs:time values can compare equal even if their timezones are different.

The order in which the sequence of values is returned is .

Which value of a set of values that compare equal is returned is .

The static type of the result is a sequence of prime types as defined in [Formal Semantics].

If the input sequence contains values of different numeric types that differ from each other by small amounts, then the eq operator is not transitive, because of rounding effects occurring during type promotion. In the situation where the input contains three values A, B, and C such that A eq B, B eq C, but A ne C, then the number of items in the result of the function (as well as the choice of which items are returned) is , subject only to the constraints that (a) no two items in the result sequence compare equal to each other, and (b) every input item that does not appear in the result sequence compares equal to some item that does appear in the result sequence.

For example, this arises when computing:

distinct-values( (xs:float('1.0'), xs:decimal('1.0000000000100000000001', xs:double( '1.00000000001'))

because the values of type xs:float and xs:double both compare equal to the value of type xs:decimal but not equal to each other.

If $arg is the empty sequence, the function returns the empty sequence.

Parameters

arg as xs:anyAtomicType

Returns

xs:anyAtomicType*

distinct-values#2

declare  function fn:distinct-values($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType* external

Returns the values that appear in a sequence, with duplicates eliminated.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

The function returns the sequence that results from removing from $arg all but one of a set of values that are equal to one another. Values are compared using the eq operator, subject to the caveats defined below.

Values of type xs:untypedAtomic are compared as if they were of type xs:string.

Values that cannot be compared, because the eq operator is not defined for their types, are considered to be distinct.

The collation used by this function is determined according to the rules in . This collation is used when string comparison is required.

For xs:float and xs:double values, positive zero is equal to negative zero and, although NaN does not equal itself, if $arg contains multiple NaN values a single NaN is returned.

If xs:dateTime, xs:date or xs:time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for the purpose of comparison. Note that xs:dateTime, xs:date or xs:time values can compare equal even if their timezones are different.

The order in which the sequence of values is returned is .

Which value of a set of values that compare equal is returned is .

The static type of the result is a sequence of prime types as defined in [Formal Semantics].

If the input sequence contains values of different numeric types that differ from each other by small amounts, then the eq operator is not transitive, because of rounding effects occurring during type promotion. In the situation where the input contains three values A, B, and C such that A eq B, B eq C, but A ne C, then the number of items in the result of the function (as well as the choice of which items are returned) is , subject only to the constraints that (a) no two items in the result sequence compare equal to each other, and (b) every input item that does not appear in the result sequence compares equal to some item that does appear in the result sequence.

For example, this arises when computing:

distinct-values( (xs:float('1.0'), xs:decimal('1.0000000000100000000001', xs:double( '1.00000000001'))

because the values of type xs:float and xs:double both compare equal to the value of type xs:decimal but not equal to each other.

If $arg is the empty sequence, the function returns the empty sequence.

Parameters

arg as xs:anyAtomicType
collation as xs:string

Returns

xs:anyAtomicType*

doc-available#1

declare  function fn:doc-available($uri as xs:string?) as xs:boolean external

The function returns true if and only if the function call fn:doc($uri) would return a document node.

This function is deterministic, context-dependent, and focus-independent. It depends on available documents, and static base uri.

If $uri is an empty sequence, this function returns false.

If a call on fn:doc($uri) would return a document node, this function returns true.

A dynamic error is raised if $uri is not a valid URI according to the rules applied by the implementation of fn:doc.

Otherwise, this function returns false.

If this function returns true, then calling fn:doc($uri) within the same must return a document node. However, if nondeterministic processing has been selected for the fn:doc function, this guarantee is lost.

Parameters

uri as xs:string

Returns

xs:boolean

doc#1

declare  function fn:doc($uri as xs:string?) as document()? external

Retrieves a document using a URI supplied as an xs:string, and returns the corresponding document node.

This function is deterministic, context-dependent, and focus-independent. It depends on available documents, and static base uri.

If $uri is the empty sequence, the result is an empty sequence.

If $uri is a relative URI reference, it is resolved relative to the value of the Static Base URI property from the static context. The resulting absolute URI is promoted to an xs:string.

If the Available documents described in provides a mapping from this string to a document node, the function returns that document node.

The URI may include a fragment identifier.

By default, this function is deterministic. Two calls on this function return the same document node if the same URI Reference (after resolution to an absolute URI Reference) is supplied to both calls. Thus, the following expression (if it does not raise an error) will always be true:

doc("foo.xml") is doc("foo.xml")

However, for performance reasons, implementations may provide a user option to evaluate the function without a guarantee of determinism. The manner in which any such option is provided is implementation-defined. If the user has not selected such an option, a call of the function must either return a deterministic result or must raise a dynamic error .

For detailed type semantics, see [Formal Semantics].

If $uri is read from a source document, it is generally appropriate to resolve it relative to the base URI property of the relevant node in the source document. This can be achieved by calling the fn:resolve-uri function, and passing the resulting absolute URI as an argument to the fn:doc function.

If two calls to this function supply different absolute URI References as arguments, the same document node may be returned if the implementation can determine that the two arguments refer to the same resource.

By defining the semantics of this function in terms of a string-to-document-node mapping in the dynamic context, the specification is acknowledging that the results of this function are outside the purview of the language specification itself, and depend entirely on the run-time environment in which the expression is evaluated. This run-time environment includes not only an unpredictable collection of resources ("the web"), but configurable machinery for locating resources and turning their contents into document nodes within the XPath data model. Both the set of resources that are reachable, and the mechanisms by which those resources are parsed and validated, are .

One possible processing model for this function is as follows. The resource identified by the URI Reference is retrieved. If the resource cannot be retrieved, a dynamic error is raised . The data resulting from the retrieval action is then parsed as an XML document and a tree is constructed in accordance with the . If the top-level media type is known and is "text", the content is parsed in the same way as if the media type were text/xml; otherwise, it is parsed in the same way as if the media type were application/xml. If the contents cannot be parsed successfully, a dynamic error is raised . Otherwise, the result of the function is the document node at the root of the resulting tree. This tree is then optionally validated against a schema.

Various aspects of this processing are . Implementations may provide external configuration options that allow any aspect of the processing to be controlled by the user. In particular:

The set of URI schemes that the implementation recognizes is implementation-defined. Implementations may allow the mapping of URIs to resources to be configured by the user, using mechanisms such as catalogs or user-written URI handlers.

The handling of non-XML media types is implementation-defined. Implementations may allow instances of the data model to be constructed from non-XML resources, under user control.

It is whether DTD validation and/or schema validation is applied to the source document.

Implementations may provide user-defined error handling options that allow processing to continue following an error in retrieving a resource, or in parsing and validating its content. When errors have been handled in this way, the function may return either an empty sequence, or a fallback document provided by the error handler.

Implementations may provide user options that relax the requirement for the function to return deterministic results.

A dynamic error may be raised if $uri is not a valid URI.

A dynamic error is raised if the available documents provides no mapping for the absolutized URI.

A dynamic error is raised if the resource cannot be retrieved or cannot be parsed successfully as XML.

A dynamic error is raised if the implementation is not able to guarantee that the result of the function will be deterministic, and the user has not indicated that an unstable result is acceptable.

Parameters

uri as xs:string

Returns

document()?

document-uri#0

declare  function fn:document-uri() as xs:anyURI? external

Returns the URI of a resource where a document can be found, if available.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If $arg is the empty sequence, the function returns the empty sequence.

If $arg is not a document node, the function returns the empty sequence.

Otherwise, the function returns the value of the document-uri accessor applied to $arg, as defined in (See ).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:anyURI?

document-uri#1

declare  function fn:document-uri($arg as node()?) as xs:anyURI? external

Returns the URI of a resource where a document can be found, if available.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If $arg is the empty sequence, the function returns the empty sequence.

If $arg is not a document node, the function returns the empty sequence.

Otherwise, the function returns the value of the document-uri accessor applied to $arg, as defined in (See ).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

xs:anyURI?

element-with-id#1

declare  function fn:element-with-id($arg as xs:string*) as element(*)* external

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.

The one-argument form of this function is deterministic, context-dependent, and focus-dependent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

The effect of this function is identical to fn:id in respect of elements that have an attribute with the is-id property. However, it behaves differently in respect of element nodes with the is-id property. Whereas the fn:id, for legacy reasons, returns the element that has the is-id property, this parent returns the element identified by the ID, which is the parent of the element having the is-id property.

The function returns a sequence, in document order with duplicates eliminated, containing every element node E that satisfies all the following conditions:

E is in the target document. The target document is the document containing $node, or the document containing the context item (.) if the second argument is omitted. The behavior of the function if $node is omitted is exactly the same as if the context item had been passed as $node.

E has an ID value equal to one of the candidate IDREF values, where:

An element has an ID value equal to V if either or both of the following conditions are true:

The element has an child element node whose is-id property (See .) is true and whose typed value is equal to V under the rules of the eq operator using the Unicode code point collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

The element has an attribute node whose is-id property (See .) is true and whose typed value is equal to V under the rules of the eq operator using the Unicode code point collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

Each xs:string in $arg is parsed as if it were of type IDREFS, that is, each xs:string in $arg is treated as a whitespace-separated sequence of tokens, each acting as an IDREF. These tokens are then included in the list of candidate IDREFs. If any of the tokens is not a lexically valid IDREF (that is, if it is not lexically an xs:NCName), it is ignored. Formally, the candidate IDREF values are the strings in the sequence given by the expression:

for $s in $arg return fn:tokenize(fn:normalize-space($s), ' ')[. castable as xs:IDREF]

If several elements have the same ID value, then E is the one that is first in document order.

A dynamic error is raised if $node, or the context item if the second argument is omitted, is a node in a tree whose root is not a document node.

The following errors may be raised when $node is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as xs:string

Returns

element(*)*

element-with-id#2

declare  function fn:element-with-id($arg as xs:string*, $node as node()) as element(*)* external

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.

The one-argument form of this function is deterministic, context-dependent, and focus-dependent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

The effect of this function is identical to fn:id in respect of elements that have an attribute with the is-id property. However, it behaves differently in respect of element nodes with the is-id property. Whereas the fn:id, for legacy reasons, returns the element that has the is-id property, this parent returns the element identified by the ID, which is the parent of the element having the is-id property.

The function returns a sequence, in document order with duplicates eliminated, containing every element node E that satisfies all the following conditions:

E is in the target document. The target document is the document containing $node, or the document containing the context item (.) if the second argument is omitted. The behavior of the function if $node is omitted is exactly the same as if the context item had been passed as $node.

E has an ID value equal to one of the candidate IDREF values, where:

An element has an ID value equal to V if either or both of the following conditions are true:

The element has an child element node whose is-id property (See .) is true and whose typed value is equal to V under the rules of the eq operator using the Unicode code point collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

The element has an attribute node whose is-id property (See .) is true and whose typed value is equal to V under the rules of the eq operator using the Unicode code point collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

Each xs:string in $arg is parsed as if it were of type IDREFS, that is, each xs:string in $arg is treated as a whitespace-separated sequence of tokens, each acting as an IDREF. These tokens are then included in the list of candidate IDREFs. If any of the tokens is not a lexically valid IDREF (that is, if it is not lexically an xs:NCName), it is ignored. Formally, the candidate IDREF values are the strings in the sequence given by the expression:

for $s in $arg return fn:tokenize(fn:normalize-space($s), ' ')[. castable as xs:IDREF]

If several elements have the same ID value, then E is the one that is first in document order.

A dynamic error is raised if $node, or the context item if the second argument is omitted, is a node in a tree whose root is not a document node.

The following errors may be raised when $node is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as xs:string
node as node()

Returns

element(*)*

empty#1

declare  function fn:empty($arg as item()*) as xs:boolean external

Returns true if the argument is the empty sequence.

This function is deterministic, context-independent, and focus-independent.

If the value of $arg is the empty sequence, the function returns true; otherwise, the function returns false.

The expression fn:empty((1,2,3)[10]) returns true().

The expression fn:empty(fn:remove(("hello", "world"), 1)) returns false().

Parameters

arg as item()

Returns

xs:boolean

encode-for-uri#1

declare  function fn:encode-for-uri($uri-part as xs:string?) as xs:string external

Encodes reserved characters in a string that is intended to be used in the path segment of a URI.

This function is deterministic, context-independent, and focus-independent.

If $uri-part is the empty sequence, the function returns the zero-length string.

This function applies the URI escaping rules defined in section 2 of 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 .

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

All characters are escaped except those identified as "unreserved" by , that is the upper- and lower-case letters A-Z, the digits 0-9, HYPHEN-MINUS ("-"), LOW LINE ("_"), FULL STOP ".", and TILDE "~".

This function escapes URI delimiters and therefore cannot be used indiscriminately to encode "invalid" characters in a path segment.

This function is invertible but not idempotent. This is because a string containing a percent character will be modified by applying the function: for example 100% becomes 100%25, while 100%25 becomes 100%2525.

Parameters

uri-part as xs:string

Returns

xs:string

ends-with#2

declare  function fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a trailing substring, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string

Returns

xs:boolean

ends-with#3

declare  function fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a trailing substring, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string
collation as xs:string

Returns

xs:boolean

environment-variable#1

declare  function fn:environment-variable($name as xs:string) as xs:string? external

Returns the value of a system environment variable, if it exists.

This function is deterministic, context-dependent, and focus-independent. It depends on environment variables.

The set of available environment variables is a set of (name, value) pairs forming part of the dynamic context, in which the name is unique within the set of pairs. The name and value are arbitrary strings.

If the $name argument matches the name of one of these pairs, the function returns the corresponding value.

If there is no environment variable with a matching name, the function returns the empty sequence.

The collation used for matching names is , but must be the same as the collation used to ensure that the names of all environment variables are unique.

The function is deterministic, which means that if it is called several times within the same execution scope, with the same arguments, it must return the same result.

On many platforms, the term "environment variable" has a natural meaning in terms of facilities provided by the operating system. This interpretation of the concept does not exclude other interpretations, such as a mapping to a set of configuration parameters in a database system.

Environment variable names are usually case sensitive. Names are usually of the form (letter|_) (letter|_|digit)*, but this varies by platform.

On some platforms, there may sometimes be multiple environment variables with the same name; in this case, it is implementation-dependent as to which is returned; see for example (Chapter 8, Environment Variables). Implementations may use prefixes or other naming conventions to disambiguate the names.

The requirement to ensure that the function is deterministic means in practice that the implementation must make a snapshot of the environment variables at some time during execution, and return values obtained from this snapshot, rather than using live values that are subject to change at any time.

Operating system environment variables may be associated with a particular process, while queries and stylesheets may execute across multiple processes (or multiple machines). In such circumstances implementations may choose to provide access to the environment variables associated with the process in which the query or stylesheet processing was initiated.

Security advice: Queries from untrusted sources should not be permitted unrestricted access to environment variables. For example, the name of the account under which the query is running may be useful information to a would-be intruder. An implementation may therefore choose to restrict access to the environment, or may provide a facility to make fn:environment-variable always return the empty sequence.

Parameters

name as xs:string

Returns

xs:string?

environment-variable#1

declare  function fn:environment-variable($arg as xs:string) as xs:string? external

Returns the value of a system environment variable, if it exists.

This function is deterministic, context-dependent, and focus-independent. It depends on environment variables.

The set of available environment variables is a set of (name, value) pairs forming part of the dynamic context, in which the name is unique within the set of pairs. The name and value are arbitrary strings.

If the $name argument matches the name of one of these pairs, the function returns the corresponding value.

If there is no environment variable with a matching name, the function returns the empty sequence.

The collation used for matching names is , but must be the same as the collation used to ensure that the names of all environment variables are unique.

The function is deterministic, which means that if it is called several times within the same execution scope, with the same arguments, it must return the same result.

On many platforms, the term "environment variable" has a natural meaning in terms of facilities provided by the operating system. This interpretation of the concept does not exclude other interpretations, such as a mapping to a set of configuration parameters in a database system.

Environment variable names are usually case sensitive. Names are usually of the form (letter|_) (letter|_|digit)*, but this varies by platform.

On some platforms, there may sometimes be multiple environment variables with the same name; in this case, it is implementation-dependent as to which is returned; see for example (Chapter 8, Environment Variables). Implementations may use prefixes or other naming conventions to disambiguate the names.

The requirement to ensure that the function is deterministic means in practice that the implementation must make a snapshot of the environment variables at some time during execution, and return values obtained from this snapshot, rather than using live values that are subject to change at any time.

Operating system environment variables may be associated with a particular process, while queries and stylesheets may execute across multiple processes (or multiple machines). In such circumstances implementations may choose to provide access to the environment variables associated with the process in which the query or stylesheet processing was initiated.

Security advice: Queries from untrusted sources should not be permitted unrestricted access to environment variables. For example, the name of the account under which the query is running may be useful information to a would-be intruder. An implementation may therefore choose to restrict access to the environment, or may provide a facility to make fn:environment-variable always return the empty sequence.

Parameters

arg as xs:string

Returns

xs:string?

error#0

declare  function fn:error() as none external

Calling the fn:error function raises an application-defined error.

This function is nondeterministic, context-independent, and focus-independent.

This function never returns a value. Instead it always raises an error. The effect of the error is identical to the effect of dynamic errors raised implicitly, for example when an incorrect argument is supplied to a function.

The parameters to the fn:error function supply information that is associated with the error condition and that is made available to a caller that asks for information about the error. The error may be caught either by the host language (using a try/catch construct in XSLT or XQuery, for example), or by the calling application or external processing environment. The way in which error information is returned to the external processing environment is

If fn:error is called with no arguments, then its behavior is the same as the function call:

fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'))

If $code is the empty sequence then the effective value is the xs:QName constructed by:

fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000')

There are three pieces of information that may be associated with an error:

The $code is an error code that distinguishes this error from others. It is an xs:QName; the namespace URI conventionally identifies the component, subsystem, or authority responsible for defining the meaning of the error code, while the local part identifies the specific error condition. The namespace URI http://www.w3.org/2005/xqt-errors is used for errors defined in this specification; other namespace URIs may be used for errors defined by the application.

If the external processing environment expects the error code to be returned as a URI or a string rather than as an xs:QName, then an error code with namespace URI NS and local part LP will be returned in the form NS#LP. The namespace URI part of the error code should therefore not include a fragment identifier.

The $description is a natural-language description of the error condition.

The $error-object is an arbitrary value used to convey additional information about the error, and may be used in any way the application chooses.

This function always raises a dynamic error. By default, it raises

Parameters

Returns

none

error#1

declare  function fn:error($code as xs:QName) as none external

Calling the fn:error function raises an application-defined error.

This function is nondeterministic, context-independent, and focus-independent.

This function never returns a value. Instead it always raises an error. The effect of the error is identical to the effect of dynamic errors raised implicitly, for example when an incorrect argument is supplied to a function.

The parameters to the fn:error function supply information that is associated with the error condition and that is made available to a caller that asks for information about the error. The error may be caught either by the host language (using a try/catch construct in XSLT or XQuery, for example), or by the calling application or external processing environment. The way in which error information is returned to the external processing environment is

If fn:error is called with no arguments, then its behavior is the same as the function call:

fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'))

If $code is the empty sequence then the effective value is the xs:QName constructed by:

fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000')

There are three pieces of information that may be associated with an error:

The $code is an error code that distinguishes this error from others. It is an xs:QName; the namespace URI conventionally identifies the component, subsystem, or authority responsible for defining the meaning of the error code, while the local part identifies the specific error condition. The namespace URI http://www.w3.org/2005/xqt-errors is used for errors defined in this specification; other namespace URIs may be used for errors defined by the application.

If the external processing environment expects the error code to be returned as a URI or a string rather than as an xs:QName, then an error code with namespace URI NS and local part LP will be returned in the form NS#LP. The namespace URI part of the error code should therefore not include a fragment identifier.

The $description is a natural-language description of the error condition.

The $error-object is an arbitrary value used to convey additional information about the error, and may be used in any way the application chooses.

This function always raises a dynamic error. By default, it raises

Parameters

code as xs:QName

Returns

none

error#2

declare  function fn:error($code as xs:QName?, $description as xs:string) as none external

Calling the fn:error function raises an application-defined error.

This function is nondeterministic, context-independent, and focus-independent.

This function never returns a value. Instead it always raises an error. The effect of the error is identical to the effect of dynamic errors raised implicitly, for example when an incorrect argument is supplied to a function.

The parameters to the fn:error function supply information that is associated with the error condition and that is made available to a caller that asks for information about the error. The error may be caught either by the host language (using a try/catch construct in XSLT or XQuery, for example), or by the calling application or external processing environment. The way in which error information is returned to the external processing environment is

If fn:error is called with no arguments, then its behavior is the same as the function call:

fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'))

If $code is the empty sequence then the effective value is the xs:QName constructed by:

fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000')

There are three pieces of information that may be associated with an error:

The $code is an error code that distinguishes this error from others. It is an xs:QName; the namespace URI conventionally identifies the component, subsystem, or authority responsible for defining the meaning of the error code, while the local part identifies the specific error condition. The namespace URI http://www.w3.org/2005/xqt-errors is used for errors defined in this specification; other namespace URIs may be used for errors defined by the application.

If the external processing environment expects the error code to be returned as a URI or a string rather than as an xs:QName, then an error code with namespace URI NS and local part LP will be returned in the form NS#LP. The namespace URI part of the error code should therefore not include a fragment identifier.

The $description is a natural-language description of the error condition.

The $error-object is an arbitrary value used to convey additional information about the error, and may be used in any way the application chooses.

This function always raises a dynamic error. By default, it raises

Parameters

code as xs:QName
description as xs:string

Returns

none

error#3

declare  function fn:error($code as xs:QName?, $description as xs:string, $error-object as item()*) as none external

Calling the fn:error function raises an application-defined error.

This function is nondeterministic, context-independent, and focus-independent.

This function never returns a value. Instead it always raises an error. The effect of the error is identical to the effect of dynamic errors raised implicitly, for example when an incorrect argument is supplied to a function.

The parameters to the fn:error function supply information that is associated with the error condition and that is made available to a caller that asks for information about the error. The error may be caught either by the host language (using a try/catch construct in XSLT or XQuery, for example), or by the calling application or external processing environment. The way in which error information is returned to the external processing environment is

If fn:error is called with no arguments, then its behavior is the same as the function call:

fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'))

If $code is the empty sequence then the effective value is the xs:QName constructed by:

fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000')

There are three pieces of information that may be associated with an error:

The $code is an error code that distinguishes this error from others. It is an xs:QName; the namespace URI conventionally identifies the component, subsystem, or authority responsible for defining the meaning of the error code, while the local part identifies the specific error condition. The namespace URI http://www.w3.org/2005/xqt-errors is used for errors defined in this specification; other namespace URIs may be used for errors defined by the application.

If the external processing environment expects the error code to be returned as a URI or a string rather than as an xs:QName, then an error code with namespace URI NS and local part LP will be returned in the form NS#LP. The namespace URI part of the error code should therefore not include a fragment identifier.

The $description is a natural-language description of the error condition.

The $error-object is an arbitrary value used to convey additional information about the error, and may be used in any way the application chooses.

This function always raises a dynamic error. By default, it raises

Parameters

code as xs:QName
description as xs:string
error-object as item()

Returns

none

escape-html-uri#1

declare  function fn:escape-html-uri($uri as xs:string?) as xs:string external

Escapes a URI in the same way that HTML user agents handle attribute values expected to contain URIs.

This function is deterministic, context-independent, and focus-independent.

If $uri is the empty sequence, the function returns the zero-length string.

Otherwise, the function escapes all characters except printable characters of the US-ASCII coded character set, specifically the codepoints between 32 and 126 (decimal) inclusive. 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.

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

Parameters

uri as xs:string

Returns

xs:string

exactly-one#1

declare  function fn:exactly-one($arg as item()*) as item() external

Returns $arg if it contains exactly one item. Otherwise, raises an error.

This function is deterministic, context-independent, and focus-independent.

Except in error cases, the function returns $arg unchanged.

For detailed type semantics, see [Formal Semantics].

A dynamic error is raised if $arg is an empty sequence or a sequence containing more than one item.

Parameters

arg as item()

Returns

item()

exists#1

declare  function fn:exists($arg as item()*) as xs:boolean external

Returns true if the argument is a non-empty sequence.

This function is deterministic, context-independent, and focus-independent.

If the value of $arg is a non-empty sequence, the function returns true; otherwise, the function returns false.

The expression fn:exists(fn:remove(("hello"), 1)) returns false().

The expression fn:exists(fn:remove(("hello", "world"), 1)) returns true().

Parameters

arg as item()

Returns

xs:boolean

false#0

declare  function fn:false() as xs:boolean external

Returns the xs:boolean value false.

This function is deterministic, context-independent, and focus-independent.

The result is equivalent to xs:boolean("0").

The expression fn:false() returns xs:boolean(0).

Parameters

Returns

xs:boolean

filter#2

declare  function fn:filter($seq as item()*, $f as function (item()) as xs:boolean) as item()* external

Returns those items from the sequence $seq for which the supplied function $f returns true.

This function is deterministic, context-independent, and focus-independent.

The effect of the function is equivalent to the following implementation in XQuery:

declare function fn:filter( $seq as item()*, $f as function(item()) as xs:boolean) as item()* { if (fn:empty($seq)) then () else ( fn:head($seq)[$f(.) eq fn:true()], fn:filter(fn:tail($seq), $f) ) };

or its equivalent in XSLT:

<xsl:function name="fn:filter" as="item()*"> <xsl:param name="seq" as="item()*"/> <xsl:param name="f" as="function(item()) as xs:boolean"/> <xsl:if test="fn:exists($seq)"> <xsl:sequence select="fn:head($seq)[$f(.) eq fn:true()], fn:filter(fn:tail($seq), $f)"/> </xsl:if> </xsl:function>

As a consequence of the function signature and the function calling rules, a type error occurs if the supplied function $f returns anything other than a single xs:boolean item; there is no conversion to an effective boolean value.

Parameters

seq as item()
f as function (item()) as xs:boolean

Returns

item()*

floor#1

declare  function fn:floor($arg as numeric?) as numeric? external

Rounds $arg downwards to a whole number.

This function is deterministic, context-independent, and focus-independent.

General rules: see .

The function returns the largest (closest to positive infinity) number with no fractional part that is not greater than the value of $arg.

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.

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.

For detailed type semantics, see [Formal Semantics].

The expression fn:floor(10.5) returns 10.

The expression fn:floor(-10.5) returns -11.

Parameters

arg as numeric

Returns

numeric?

fold-left#3

declare  function fn:fold-left($seq as item()*, $zero as item()*, $f as function (item()*, item()) as item()*) as item()* external

Processes the supplied sequence from left to right, applying the supplied function repeatedly to each item in turn, together with an accumulated result value.

This function is deterministic, context-independent, and focus-independent.

The effect of the function is equivalent to the following implementation in XQuery:

declare function fn:fold-left( $seq as item()* $zero as item()*, $f as function(item()*, item()) as item()*) as item()* { if (fn:empty($seq)) then $zero else fn:fold-left(fn:tail($seq), $f($zero, fn:head($seq)), $f) };

or its equivalent in XSLT:

<xsl:function name="fn:fold-left" as="item()*"> <xsl:param name="seq" as="item()*"/> <xsl:param name="zero" as="item()*"/> <xsl:param name="f" as="function(item()*, item()) as item()*"/> <xsl:choose> <xsl:when test="fn:empty($seq)"> <xsl:sequence select="$zero"/> </xsl:when> <xsl:otherwise> <xsl:sequence select="fn:fold-left(fn:tail($seq), $f($zero, fn:head($seq)), $f)"/> </xsl:otherwise> </xsl:choose> </xsl:function>

As a consequence of the function signature and the function calling rules, a type error occurs if the supplied function $f cannot be applied to two arguments, where the first argument is either the value of $zero or the result of a previous application of $f, and the second is $seq or any trailing subsequence of $seq.

Parameters

seq as item()
zero as item()
f as function (item()*, item()) as item()*

Returns

item()*

fold-right#3

declare  function fn:fold-right($seq as item()*, $zero as item()*, $f as function (item()*, item()) as item()*) as item()* external

Processes the supplied sequence from right to left, applying the supplied function repeatedly to each item in turn, together with an accumulated result value.

This function is deterministic, context-independent, and focus-independent.

The effect of the function is equivalent to the following implementation in XQuery:

declare function fn:fold-right( $seq as item()*, $zero as item()*, $f as function(item(), item()*) as item()*) as item()* { if (fn:empty($seq)) then $zero else $f(fn:head($seq), fn:fold-right(fn:tail($seq), $zero, $f)) };

or its equivalent in XSLT:

<xsl:function name="fn:fold-right" as="item()*"> <xsl:param name="seq" as="item()*"/> <xsl:param name="zero" as="item()*"/> <xsl:param name="f" as="function(item(), item()*) as item()*"/> <xsl:choose> <xsl:when test="fn:empty($seq)"> <xsl:sequence select="$zero"/> </xsl:when> <xsl:otherwise> <xsl:sequence select="$f(fn:head($seq), fn:fold-right(fn:tail($seq), $zero, $f))"/> </xsl:otherwise> </xsl:choose> </xsl:function>

As a consequence of the function signature and the function calling rules, a type error occurs if the supplied function $f cannot be applied to two arguments, where the first argument is any item in the sequence $seq, and the second is either the value of $zero or the result of a previous application of $f.

Parameters

seq as item()
zero as item()
f as function (item()*, item()) as item()*

Returns

item()*

for-each-pair#3

declare  function fn:for-each-pair($seq1 as item()*, $seq2 as item()*, $f as function (item(), item()) as item()*) as item()* external

Applies the function item $f to successive pairs of items taken one from $seq1 and one from $seq2, returning the concatenation of the resulting sequences in order.

This function is deterministic, context-independent, and focus-independent.

The effect of the function is equivalent to the following implementation in XQuery:

declare function fn:for-each-pair($seq1, $seq2, $f) { if(fn:exists($seq1) and fn:exists($seq2)) then ( $f(fn:head($seq1), fn:head($seq2)), fn:for-each-pair(fn:tail($seq1), fn:tail($seq2), $f) ) else () };

or its equivalent in XSLT:

<xsl:function name="fn:for-each-pair"> <xsl:param name="seq1/> <xsl:param name="seq2/> <xsl:param name="f"/> <xsl:if test="fn:exists($seq1) and fn:exists($seq2)"> <xsl:sequence select="$f(fn:head($seq1), fn:head($seq2))"/> <xsl:sequence select="fn:for-each-pair(fn:tail($seq1), fn:tail($seq2), $f)"/> </xsl:if> </xsl:function>

The expression fn:for-each-pair(("a", "b", "c"), ("x", "y", "z"), concat#2) returns ("ax", "by", "cz").

The expression fn:for-each-pair(1 to 5, 1 to 5, function($a, $b){10*$a + $b} returns (11, 22, 33, 44, 55).

Parameters

seq1 as item()
seq2 as item()
f as function (item(), item()) as item()*

Returns

item()*

for-each#2

declare  function fn:for-each($seq as item()*, $f as function (item()) as item()*) as item()* external

Applies the function item $f to every item from the sequence $seq in turn, returning the concatenation of the resulting sequences in order.

This function is deterministic, context-independent, and focus-independent.

The effect of the function is equivalent to the following implementation in XQuery:

declare function fn:for-each($seq, $f) { if (fn:empty($seq)) then () else ($f(fn:head($seq)), fn:for-each(fn:tail($seq), $f)) };

or its equivalent in XSLT:

<xsl:function name="fn:for-each"> <xsl:param name="seq"/> <xsl:param name="f"/> <xsl:if test="fn:exists($seq)"> <xsl:sequence select="$f(fn:head($seq)), fn:for-each(fn:tail($seq), $f)"/> </xsl:if> </xsl:function>

The function call fn:for-each($SEQ, $F) is equivalent to the expression for $i in $SEQ return $F($i), assuming that ordering mode is ordered.

Parameters

seq as item()
f as function (item()) as item()*

Returns

item()*

format-date#2

declare  function fn:format-date($value as xs:date?, $picture as xs:string) as xs:string? external

Returns a string containing an xs:date value formatted for display.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on default calendar, and default language, and default place, and implicit timezone.

The five-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone, and namespaces.

See .

Parameters

value as xs:date
picture as xs:string

Returns

xs:string?

format-date#5

declare  function fn:format-date($value as xs:date?, $picture as xs:string, $language as xs:string?, $calendar as xs:string?, $place as xs:string?) as xs:string? external

Returns a string containing an xs:date value formatted for display.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on default calendar, and default language, and default place, and implicit timezone.

The five-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone, and namespaces.

See .

Parameters

value as xs:date
picture as xs:string
language as xs:string
calendar as xs:string
place as xs:string

Returns

xs:string?

format-dateTime#2

declare  function fn:format-dateTime($value as xs:dateTime?, $picture as xs:string) as xs:string? external

Returns a string containing an xs:dateTime value formatted for display.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on default calendar, and default language, and default place, and implicit timezone.

The five-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone, and namespaces.

See .

Parameters

value as xs:dateTime
picture as xs:string

Returns

xs:string?

format-dateTime#5

declare  function fn:format-dateTime($value as xs:dateTime?, $picture as xs:string, $language as xs:string?, $calendar as xs:string?, $place as xs:string?) as xs:string? external

Returns a string containing an xs:dateTime value formatted for display.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on default calendar, and default language, and default place, and implicit timezone.

The five-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone, and namespaces.

See .

Parameters

value as xs:dateTime
picture as xs:string
language as xs:string
calendar as xs:string
place as xs:string

Returns

xs:string?

format-integer#2

declare  function fn:format-integer($value as xs:integer?, $picture as xs:string) as xs:string external

Formats an integer according to a given picture string, using the conventions of a given natural language if specified.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on default language.

The three-argument form of this function is deterministic, context-independent, and focus-independent.

If $value is an empty sequence, the function returns a zero-length string.

In all other cases, the $picture argument describes the format in which $value is output.

The rules that follow describe how non-negative numbers are output. If the value of $value is negative, the rules below are applied to the absolute value of $value, and a minus sign is prepended to the result.

The value of $picture consists of a primary format token, optionally followed by a format modifier. The primary format token is always present and must not be zero-length. If the string contains one or more semicolons then everything that precedes the last semicolon is taken as the primary format token and everything that follows is taken as the format modifier; if the string contains no semicolon then the entire picture is taken as the primary format token, and the format modifier is taken to be absent (which is equivalent to supplying a zero-length string).

The primary format token is classified as one of the following:

A decimal-digit-pattern made up of optional-digit-signs, mandatory-digit-signs, and grouping-separator-signs.

The optional-digit-sign is the character "#".

A mandatory-digit-sign is a character in Unicode category Nd. All mandatory-digit-signs within the format token must be from the same digit family, where a digit family is a sequence of ten consecutive characters in Unicode category Nd, having digit values 0 through 9. Within the format token, these digits are interchangeable: a three-digit number may thus be indicated equivalently by 000, 001, or 999.

a grouping-separator-sign is a non-alphanumeric character, that is a character whose Unicode category is other than Nd, Nl, No, Lu, Ll, Lt, Lm or Lo.

If the primary format token contains at least one Unicode digit then it is taken as a decimal digit pattern, and in this case it must match the regular expression ^((\p{Nd}|#|[^\p{N}\p{L}])+?)$. If it contains a digit but does not match this pattern, a dynamic error is raised .

If a semicolon is to be used as a grouping separator, then the primary format token as a whole must be followed by another semicolon, to ensure that the grouping separator is not mistaken as a separator between the primary format token and the format modifier.

There must be at least one mandatory-digit-sign. There may be zero or more optional-digit-signs, and (if present) these must precede all mandatory-digit-signs. There may be zero or more grouping-separator-signs. A grouping-separator-sign must not appear at the start or end of the decimal-digit-pattern, nor adjacent to another grouping-separator-sign.

The corresponding output format is a decimal number, using this digit family, with at least as many digits as there are mandatory-digit-signs in the format token. Thus, a format token 1 generates the sequence 0 1 2 ... 10 11 12 ..., and a format token 01 (or equivalently, 00 or 99) generates the sequence 00 01 02 ... 09 10 11 12 ... 99 100 101. A format token of &#x661; (Arabic-Indic digit one) generates the sequence ١ then ٢ then ٣ ...

The grouping-separator-signs are handled as follows. The position of grouping separators within the format token, counting backwards from the last digit, indicates the position of grouping separators to appear within the formatted number, and the character used as the grouping-separator-sign within the format token indicates the character to be used as the corresponding grouping separator in the formatted number. If grouping-separator-signs appear at regular intervals within the format token, that is if the same grouping separator appears at positions forming a sequence N, 2N, 3N, ... for some integer value N (including the case where there is only one number in the list), then the sequence is extrapolated to the left, so grouping separators will be used in the formatted number at every multiple of N. For example, if the format token is 0'000 then the number one million will be formatted as 1'000'000, while the number fifteen will be formatted as 0'015.

The only purpose of optional-digit-signs is to mark the position of grouping-separator-signs. For example, if the format token is #'##0 then the number one million will be formatted as 1'000'000, while the number fifteen will be formatted as 15. A grouping separator is included in the formatted number only if there is a digit to its left, which will only be the case if either (a) the number is large enough to require that digit, or (b) the number of mandatory-digit-signs in the format token requires insignificant leading zeros to be present.

Numbers will never be truncated. Given the decimal-digit-pattern 01, the number three hundred will be output as 300, despite the absence of any optional-digit-sign.

The format token A, which generates the sequence A B C ... Z AA AB AC....

The format token a, which generates the sequence a b c ... z aa ab ac....

The format token i, which generates the sequence i ii iii iv v vi vii viii ix x ....

The format token I, which generates the sequence I II III IV V VI VII VIII IX X ....

The format token w, which generates numbers written as lower-case words, for example in English, one two three four ...

The format token W, which generates numbers written as upper-case words, for example in English, ONE TWO THREE FOUR ...

The format token Ww, which generates numbers written as title-case words, for example in English, One Two Three Four ...

Any other format token, which indicates a numbering sequence in which that token represents the number 1 (one) (but see the note below). It is implementation-defined which numbering sequences, additional to those listed above, are supported. If an implementation does not support a numbering sequence represented by the given token, it must use a format token of 1.

In some traditional numbering sequences additional signs are added to denote that the letters should be interpreted as numbers; these are not included in the format token. An example (see also the example below) is classical Greek where a dexia keraia (x0374, ʹ) and sometimes an aristeri keraia (x0375, ͵) is added.

For all format tokens other than the first kind above (one that consists of decimal digits), there may be implementation-defined lower and upper bounds on the range of numbers that can be formatted using this format token; indeed, for some numbering sequences there may be intrinsic limits. For example, the format token &#x2460; (circled digit one, ①) has a range imposed by the Unicode character repertoire — 1 to 20 in Unicode versions prior to 4.0, increased in subsequent versions. For the numbering sequences described above any upper bound imposed by the implementation must not be less than 1000 (one thousand) and any lower bound must not be greater than 1. Numbers that fall outside this range must be formatted using the format token 1.

The above expansions of numbering sequences for format tokens such as a and i are indicative but not prescriptive. There are various conventions in use for how alphabetic sequences continue when the alphabet is exhausted, and differing conventions for how roman numerals are written (for example, IV versus IIII as the representation of the number 4). Sometimes alphabetic sequences are used that omit letters such as i and o. This specification does not prescribe the detail of any sequence other than those sequences consisting entirely of decimal digits.

Many numbering sequences are language-sensitive. This applies especially to the sequence selected by the tokens w, W and Ww. It also applies to other sequences, for example different languages using the Cyrillic alphabet use different sequences of characters, each starting with the letter #x410 (Cyrillic capital letter A). In such cases, the $lang argument specifies which language's conventions are to be used. If the argument is specified, the value should be either an empty sequence or a value that would be valid for the xml:lang attribute (see ). Note that this permits the identification of sublanguages based on country codes (from ISO 3166-1) as well as identification of dialects and regions within a country..

The set of languages for which numbering is supported is . If the $lang argument is absent, or is set to an empty sequence, or is invalid, or is not a language supported by the implementation, then the number is formatted using the default language from the dynamic context.

The format modifier must be a string that matches the regular expression ^([co](\(.+\))?)?[at]?$. That is, if it is present it must consist of one or more of the following, in any order:

either c or o, optionally followed by a sequence of characters enclosed between parentheses, to indicate cardinal or ordinal numbering respectively, the default being cardinal numbering

either a or t, to indicate alphabetic or traditional numbering respectively, the default being implementation-defined.

If the o modifier is present, this indicates a request to output ordinal numbers rather than cardinal numbers. For example, in English, when used with the format token 1, this outputs the sequence 1st 2nd 3rd 4th ..., and when used with the format token w outputs the sequence first second third fourth ....

The string of characters between the parentheses, if present, is used to select between other possible variations of cardinal or ordinal numbering sequences. The interpretation of this string is implementation-defined. No error occurs if the implementation does not define any interpretation for the defined string.

For example, in some languages, ordinal numbers vary depending on the grammatical context: they may have different genders and may decline with the noun that they qualify. In such cases the string appearing in parentheses after the letter o may be used to indicate the variation of the ordinal number required. The way in which the variation is indicated will depend on the conventions of the language. For inflected languages that vary the ending of the word, the recommended approach is to indicate the required ending, preceded by a hyphen: for example in German, appropriate values are o(-e), o(-er), o(-es), o(-en).

It is implementation-defined what combinations of values of the format token, the language, and the cardinal/ordinal modifier are supported. If ordinal numbering is not supported for the combination of the format token, the language, and the string appearing in parentheses, the request is ignored and cardinal numbers are generated instead.

Ordinal Numbering in Italian

The specification "1;o(-º)" with $lang equal to it, if supported, should produce the sequence:

1º 2º 3º 4º ...

The specification "Ww;o" with $lang equal to it, if supported, should produce the sequence:

Primo Secondo Terzo Quarto Quinto ...

The use of the a or t modifier disambiguates between numbering sequences that use letters. In many languages there are two commonly used numbering sequences that use letters. One numbering sequence assigns numeric values to letters in alphabetic sequence, and the other assigns numeric values to each letter in some other manner traditional in that language. In English, these would correspond to the numbering sequences specified by the format tokens a and i. In some languages, the first member of each sequence is the same, and so the format token alone would be ambiguous. In the absence of the a or t modifier, the default is implementation-defined.

A dynamic error is raised if the format token is invalid, that is, if it violates any mandatory rules (indicated by an emphasized must or required keyword in the above rules). For example, the error is raised if the primary format token contains a digit but does not match the required regular expression.

Parameters

value as xs:integer
picture as xs:string

Returns

xs:string

format-integer#3

declare  function fn:format-integer($value as xs:integer?, $picture as xs:string, $language as xs:string) as xs:string external

Formats an integer according to a given picture string, using the conventions of a given natural language if specified.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on default language.

The three-argument form of this function is deterministic, context-independent, and focus-independent.

If $value is an empty sequence, the function returns a zero-length string.

In all other cases, the $picture argument describes the format in which $value is output.

The rules that follow describe how non-negative numbers are output. If the value of $value is negative, the rules below are applied to the absolute value of $value, and a minus sign is prepended to the result.

The value of $picture consists of a primary format token, optionally followed by a format modifier. The primary format token is always present and must not be zero-length. If the string contains one or more semicolons then everything that precedes the last semicolon is taken as the primary format token and everything that follows is taken as the format modifier; if the string contains no semicolon then the entire picture is taken as the primary format token, and the format modifier is taken to be absent (which is equivalent to supplying a zero-length string).

The primary format token is classified as one of the following:

A decimal-digit-pattern made up of optional-digit-signs, mandatory-digit-signs, and grouping-separator-signs.

The optional-digit-sign is the character "#".

A mandatory-digit-sign is a character in Unicode category Nd. All mandatory-digit-signs within the format token must be from the same digit family, where a digit family is a sequence of ten consecutive characters in Unicode category Nd, having digit values 0 through 9. Within the format token, these digits are interchangeable: a three-digit number may thus be indicated equivalently by 000, 001, or 999.

a grouping-separator-sign is a non-alphanumeric character, that is a character whose Unicode category is other than Nd, Nl, No, Lu, Ll, Lt, Lm or Lo.

If the primary format token contains at least one Unicode digit then it is taken as a decimal digit pattern, and in this case it must match the regular expression ^((\p{Nd}|#|[^\p{N}\p{L}])+?)$. If it contains a digit but does not match this pattern, a dynamic error is raised .

If a semicolon is to be used as a grouping separator, then the primary format token as a whole must be followed by another semicolon, to ensure that the grouping separator is not mistaken as a separator between the primary format token and the format modifier.

There must be at least one mandatory-digit-sign. There may be zero or more optional-digit-signs, and (if present) these must precede all mandatory-digit-signs. There may be zero or more grouping-separator-signs. A grouping-separator-sign must not appear at the start or end of the decimal-digit-pattern, nor adjacent to another grouping-separator-sign.

The corresponding output format is a decimal number, using this digit family, with at least as many digits as there are mandatory-digit-signs in the format token. Thus, a format token 1 generates the sequence 0 1 2 ... 10 11 12 ..., and a format token 01 (or equivalently, 00 or 99) generates the sequence 00 01 02 ... 09 10 11 12 ... 99 100 101. A format token of &#x661; (Arabic-Indic digit one) generates the sequence ١ then ٢ then ٣ ...

The grouping-separator-signs are handled as follows. The position of grouping separators within the format token, counting backwards from the last digit, indicates the position of grouping separators to appear within the formatted number, and the character used as the grouping-separator-sign within the format token indicates the character to be used as the corresponding grouping separator in the formatted number. If grouping-separator-signs appear at regular intervals within the format token, that is if the same grouping separator appears at positions forming a sequence N, 2N, 3N, ... for some integer value N (including the case where there is only one number in the list), then the sequence is extrapolated to the left, so grouping separators will be used in the formatted number at every multiple of N. For example, if the format token is 0'000 then the number one million will be formatted as 1'000'000, while the number fifteen will be formatted as 0'015.

The only purpose of optional-digit-signs is to mark the position of grouping-separator-signs. For example, if the format token is #'##0 then the number one million will be formatted as 1'000'000, while the number fifteen will be formatted as 15. A grouping separator is included in the formatted number only if there is a digit to its left, which will only be the case if either (a) the number is large enough to require that digit, or (b) the number of mandatory-digit-signs in the format token requires insignificant leading zeros to be present.

Numbers will never be truncated. Given the decimal-digit-pattern 01, the number three hundred will be output as 300, despite the absence of any optional-digit-sign.

The format token A, which generates the sequence A B C ... Z AA AB AC....

The format token a, which generates the sequence a b c ... z aa ab ac....

The format token i, which generates the sequence i ii iii iv v vi vii viii ix x ....

The format token I, which generates the sequence I II III IV V VI VII VIII IX X ....

The format token w, which generates numbers written as lower-case words, for example in English, one two three four ...

The format token W, which generates numbers written as upper-case words, for example in English, ONE TWO THREE FOUR ...

The format token Ww, which generates numbers written as title-case words, for example in English, One Two Three Four ...

Any other format token, which indicates a numbering sequence in which that token represents the number 1 (one) (but see the note below). It is implementation-defined which numbering sequences, additional to those listed above, are supported. If an implementation does not support a numbering sequence represented by the given token, it must use a format token of 1.

In some traditional numbering sequences additional signs are added to denote that the letters should be interpreted as numbers; these are not included in the format token. An example (see also the example below) is classical Greek where a dexia keraia (x0374, ʹ) and sometimes an aristeri keraia (x0375, ͵) is added.

For all format tokens other than the first kind above (one that consists of decimal digits), there may be implementation-defined lower and upper bounds on the range of numbers that can be formatted using this format token; indeed, for some numbering sequences there may be intrinsic limits. For example, the format token &#x2460; (circled digit one, ①) has a range imposed by the Unicode character repertoire — 1 to 20 in Unicode versions prior to 4.0, increased in subsequent versions. For the numbering sequences described above any upper bound imposed by the implementation must not be less than 1000 (one thousand) and any lower bound must not be greater than 1. Numbers that fall outside this range must be formatted using the format token 1.

The above expansions of numbering sequences for format tokens such as a and i are indicative but not prescriptive. There are various conventions in use for how alphabetic sequences continue when the alphabet is exhausted, and differing conventions for how roman numerals are written (for example, IV versus IIII as the representation of the number 4). Sometimes alphabetic sequences are used that omit letters such as i and o. This specification does not prescribe the detail of any sequence other than those sequences consisting entirely of decimal digits.

Many numbering sequences are language-sensitive. This applies especially to the sequence selected by the tokens w, W and Ww. It also applies to other sequences, for example different languages using the Cyrillic alphabet use different sequences of characters, each starting with the letter #x410 (Cyrillic capital letter A). In such cases, the $lang argument specifies which language's conventions are to be used. If the argument is specified, the value should be either an empty sequence or a value that would be valid for the xml:lang attribute (see ). Note that this permits the identification of sublanguages based on country codes (from ISO 3166-1) as well as identification of dialects and regions within a country..

The set of languages for which numbering is supported is . If the $lang argument is absent, or is set to an empty sequence, or is invalid, or is not a language supported by the implementation, then the number is formatted using the default language from the dynamic context.

The format modifier must be a string that matches the regular expression ^([co](\(.+\))?)?[at]?$. That is, if it is present it must consist of one or more of the following, in any order:

either c or o, optionally followed by a sequence of characters enclosed between parentheses, to indicate cardinal or ordinal numbering respectively, the default being cardinal numbering

either a or t, to indicate alphabetic or traditional numbering respectively, the default being implementation-defined.

If the o modifier is present, this indicates a request to output ordinal numbers rather than cardinal numbers. For example, in English, when used with the format token 1, this outputs the sequence 1st 2nd 3rd 4th ..., and when used with the format token w outputs the sequence first second third fourth ....

The string of characters between the parentheses, if present, is used to select between other possible variations of cardinal or ordinal numbering sequences. The interpretation of this string is implementation-defined. No error occurs if the implementation does not define any interpretation for the defined string.

For example, in some languages, ordinal numbers vary depending on the grammatical context: they may have different genders and may decline with the noun that they qualify. In such cases the string appearing in parentheses after the letter o may be used to indicate the variation of the ordinal number required. The way in which the variation is indicated will depend on the conventions of the language. For inflected languages that vary the ending of the word, the recommended approach is to indicate the required ending, preceded by a hyphen: for example in German, appropriate values are o(-e), o(-er), o(-es), o(-en).

It is implementation-defined what combinations of values of the format token, the language, and the cardinal/ordinal modifier are supported. If ordinal numbering is not supported for the combination of the format token, the language, and the string appearing in parentheses, the request is ignored and cardinal numbers are generated instead.

Ordinal Numbering in Italian

The specification "1;o(-º)" with $lang equal to it, if supported, should produce the sequence:

1º 2º 3º 4º ...

The specification "Ww;o" with $lang equal to it, if supported, should produce the sequence:

Primo Secondo Terzo Quarto Quinto ...

The use of the a or t modifier disambiguates between numbering sequences that use letters. In many languages there are two commonly used numbering sequences that use letters. One numbering sequence assigns numeric values to letters in alphabetic sequence, and the other assigns numeric values to each letter in some other manner traditional in that language. In English, these would correspond to the numbering sequences specified by the format tokens a and i. In some languages, the first member of each sequence is the same, and so the format token alone would be ambiguous. In the absence of the a or t modifier, the default is implementation-defined.

A dynamic error is raised if the format token is invalid, that is, if it violates any mandatory rules (indicated by an emphasized must or required keyword in the above rules). For example, the error is raised if the primary format token contains a digit but does not match the required regular expression.

Parameters

value as xs:integer
picture as xs:string
language as xs:string

Returns

xs:string

format-number#2

declare  function fn:format-number($value as numeric?, $picture as xs:string) as xs:string external

Returns a string containing a number formatted according to a given picture string, taking account of decimal formats specified in the static context.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on decimal formats, and namespaces.

The effect of the two-argument form of the function is equivalent to calling the three-argument form with an empty sequence as the value of the third argument.

The function formats $value as a string using the picture string specified by the $picture argument and the decimal-format named by the $decimal-format-name argument, or the default decimal-format, if there is no $decimal-format-name argument. The syntax of the picture string is described in .

The $value argument may be of any numeric data type (xs:double, xs:float, xs:decimal, or their subtypes including xs:integer). Note that if an xs:decimal is supplied, it is not automatically promoted to an xs:double, as such promotion can involve a loss of precision.

If the supplied value of the $value argument is an empty sequence, the function behaves as if the supplied value were the xs:double value NaN.

The value of $decimal-format-name, if present and non-empty, must be a string which after removal of leading and trailing whitespace is in the form of an an EQName as defined in the XPath 3.0 grammar, that is one of the following:

A lexical QName, which is expanded using the statically known namespaces. The default namespace is not used (no prefix means no namespace).

A URIQualifiedName using the syntax Q{uri}local, where the URI can be zero-length to indicate a name in no namespace.

The decimal format that is used is the decimal format in the static context whose name matches $decimal-format-name if supplied, or the default decimal format in the static context otherwise.

The evaluation of the format-number function takes place in two phases, an analysis phase described in and a formatting phase described in .

The analysis phase takes as its inputs the picture string and the variables derived from the relevant decimal format in the static context, and produces as its output a number of variables with defined values. The formatting phase takes as its inputs the number to be formatted and the variables produced by the analysis phase, and produces as its output a string containing a formatted representation of the number.

The result of the function is the formatted string representation of the supplied number.

A dynamic error is raised if the name specified as the $decimal-format-name argument is neither a valid lexical QName nor a valid URIQualifiedName, or if it uses a prefix that is not found in the statically known namespaces, or if the static context does not contain a declaration of a decimal-format with a matching expanded QName. If the processor is able to detect the error statically (for example, when the argument is supplied as a string literal), then the processor may optionally signal this as a static error.

Parameters

value as numeric
picture as xs:string

Returns

xs:string

format-number#3

declare  function fn:format-number($value as numeric?, $picture as xs:string, $decimal-format-name as xs:string) as xs:string external

Returns a string containing a number formatted according to a given picture string, taking account of decimal formats specified in the static context.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on decimal formats, and namespaces.

The effect of the two-argument form of the function is equivalent to calling the three-argument form with an empty sequence as the value of the third argument.

The function formats $value as a string using the picture string specified by the $picture argument and the decimal-format named by the $decimal-format-name argument, or the default decimal-format, if there is no $decimal-format-name argument. The syntax of the picture string is described in .

The $value argument may be of any numeric data type (xs:double, xs:float, xs:decimal, or their subtypes including xs:integer). Note that if an xs:decimal is supplied, it is not automatically promoted to an xs:double, as such promotion can involve a loss of precision.

If the supplied value of the $value argument is an empty sequence, the function behaves as if the supplied value were the xs:double value NaN.

The value of $decimal-format-name, if present and non-empty, must be a string which after removal of leading and trailing whitespace is in the form of an an EQName as defined in the XPath 3.0 grammar, that is one of the following:

A lexical QName, which is expanded using the statically known namespaces. The default namespace is not used (no prefix means no namespace).

A URIQualifiedName using the syntax Q{uri}local, where the URI can be zero-length to indicate a name in no namespace.

The decimal format that is used is the decimal format in the static context whose name matches $decimal-format-name if supplied, or the default decimal format in the static context otherwise.

The evaluation of the format-number function takes place in two phases, an analysis phase described in and a formatting phase described in .

The analysis phase takes as its inputs the picture string and the variables derived from the relevant decimal format in the static context, and produces as its output a number of variables with defined values. The formatting phase takes as its inputs the number to be formatted and the variables produced by the analysis phase, and produces as its output a string containing a formatted representation of the number.

The result of the function is the formatted string representation of the supplied number.

A dynamic error is raised if the name specified as the $decimal-format-name argument is neither a valid lexical QName nor a valid URIQualifiedName, or if it uses a prefix that is not found in the statically known namespaces, or if the static context does not contain a declaration of a decimal-format with a matching expanded QName. If the processor is able to detect the error statically (for example, when the argument is supplied as a string literal), then the processor may optionally signal this as a static error.

Parameters

value as numeric
picture as xs:string
decimal-format-name as xs:string

Returns

xs:string

format-time#2

declare  function fn:format-time($value as xs:time?, $picture as xs:string) as xs:string? external

Returns a string containing an xs:time value formatted for display.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on default calendar, and default language, and default place, and implicit timezone.

The five-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone, and namespaces.

See .

Parameters

value as xs:time
picture as xs:string

Returns

xs:string?

format-time#5

declare  function fn:format-time($value as xs:time?, $picture as xs:string, $language as xs:string?, $calendar as xs:string?, $place as xs:string?) as xs:string? external

Returns a string containing an xs:time value formatted for display.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on default calendar, and default language, and default place, and implicit timezone.

The five-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone, and namespaces.

See .

Parameters

value as xs:time
picture as xs:string
language as xs:string
calendar as xs:string
place as xs:string

Returns

xs:string?

function-arity#1

declare  function fn:function-arity($func as function (*)) as xs:integer external

Returns the arity of the function identified by a function item.

This function is deterministic, context-independent, and focus-independent.

The fn:function-arity function returns the arity (number of arguments) of the function identified by $func.

The expression fn:function-arity(fn:substring#2) returns 2.

The expression fn:function-arity(function($node){name($node)}) returns 1.

The expression let $initial := fn:substring(?, 1, 1) return fn:function-arity($initial) returns 1.

Parameters

func as function (*)

Returns

xs:integer

generate-id#0

declare  function fn:generate-id() as xs:string external

This function returns a string that uniquely identifies a given node.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If the argument is the empty sequence, the result is the zero-length string.

In other cases, the function returns a string that uniquely identifies a given node.

The returned identifier must consist of ASCII alphanumeric characters and must start with an alphabetic character. Thus, the string is syntactically an XML name.

An implementation is free to generate an identifier in any convenient way provided that it always generates the same identifier for the same node and that different identifiers are always generated from different nodes. An implementation is under no obligation to generate the same identifiers each time a document is transformed or queried.

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:string

generate-id#1

declare  function fn:generate-id($arg as node()?) as xs:string external

This function returns a string that uniquely identifies a given node.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If the argument is the empty sequence, the result is the zero-length string.

In other cases, the function returns a string that uniquely identifies a given node.

The returned identifier must consist of ASCII alphanumeric characters and must start with an alphabetic character. Thus, the string is syntactically an XML name.

An implementation is free to generate an identifier in any convenient way provided that it always generates the same identifier for the same node and that different identifiers are always generated from different nodes. An implementation is under no obligation to generate the same identifiers each time a document is transformed or queried.

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

xs:string

has-children#0

declare  function fn:has-children() as xs:boolean external

Returns true if the supplied node has one or more child nodes (of any kind).

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

Provided that the supplied argument $node matches the expected type node()?, the result of the function call fn:has-children($node) is defined to be the same as the result of the expression fn:exists($node/child::node()).

The following errors may be raised when $node is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:boolean

has-children#1

declare  function fn:has-children($node as node()?) as xs:boolean external

Returns true if the supplied node has one or more child nodes (of any kind).

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

Provided that the supplied argument $node matches the expected type node()?, the result of the function call fn:has-children($node) is defined to be the same as the result of the expression fn:exists($node/child::node()).

The following errors may be raised when $node is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

node as node()

Returns

xs:boolean

head#1

declare  function fn:head($arg as item()*) as item()? external

Returns the first item in a sequence.

This function is deterministic, context-independent, and focus-independent.

The function returns the value of the expression $arg[1]

If $arg is the empty sequence, the empty sequence is returned. Otherwise the first item in the sequence is returned.

Parameters

arg as item()

Returns

item()?

hours-from-duration#1

declare  function fn:hours-from-duration($arg as xs:duration?) as xs:integer? external

Returns the number of hours in a duration.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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 ) and then computing the hours component as described in .

If $arg is a negative duration then the result will be negative..

If $arg is an xs:yearMonthDuration the function returns 0.

The expression fn:hours-from-duration(xs:dayTimeDuration("P3DT10H")) returns 10.

The expression fn:hours-from-duration(xs:dayTimeDuration("P3DT12H32M12S")) returns 12.

The expression fn:hours-from-duration(xs:dayTimeDuration("PT123H")) returns 3.

The expression fn:hours-from-duration(xs:dayTimeDuration("-P3DT10H")) returns -10.

Parameters

arg as xs:duration

Returns

xs:integer?

hours-from-time#1

declare  function fn:hours-from-time($arg as xs:time?) as xs:integer? external

Returns the hours component of an xs:time.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:integer between 0 and 23, both inclusive, representing the value of the hours component in the local value of $arg.

Assume that the dynamic context provides an implicit timezone value of -05:00.

The expression fn:hours-from-time(xs:time("11:23:00")) returns 11.

The expression fn:hours-from-time(xs:time("21:23:00")) returns 21.

The expression fn:hours-from-time(xs:time("01:23:00+05:00")) returns 1.

The expression fn:hours-from-time(fn:adjust-time-to-timezone(xs:time("01:23:00+05:00"), xs:dayTimeDuration("PT0S"))) returns 20.

The expression fn:hours-from-time(xs:time("24:00:00")) returns 0.

Parameters

arg as xs:time

Returns

xs:integer?

id#1

declare  function fn:id($arg as xs:string*) as element(*)* external

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.

The one-argument form of this function is deterministic, context-dependent, and focus-dependent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

The function returns a sequence, in document order with duplicates eliminated, containing every element node E that satisfies all the following conditions:

E is in the target document. The target document is the document containing $node, or the document containing the context item (.) if the second argument is omitted. The behavior of the function if $node is omitted is exactly the same as if the context item had been passed as $node.

E has an ID value equal to one of the candidate IDREF values, where:

An element has an ID value equal to V if either or both of the following conditions are true:

The is-id property (See .) of the element node is true, and the typed value of the element node is equal to V under the rules of the eq operator using the Unicode codepoint collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

The element has an attribute node whose is-id property (See .) is true and whose typed value is equal to V under the rules of the eq operator using the Unicode code point collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

Each xs:string in $arg is parsed as if it were of type IDREFS, that is, each xs:string in $arg is treated as a whitespace-separated sequence of tokens, each acting as an IDREF. These tokens are then included in the list of candidate IDREFs. If any of the tokens is not a lexically valid IDREF (that is, if it is not lexically an xs:NCName), it is ignored. Formally, the candidate IDREF values are the strings in the sequence given by the expression:

for $s in $arg return fn:tokenize(fn:normalize-space($s), ' ')[. castable as xs:IDREF]

If several elements have the same ID value, then E is the one that is first in document order.

A dynamic error is raised if $node, or the context item if the second argument is absent, is a node in a tree whose root is not a document node.

The following errors may be raised when $node is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as xs:string

Returns

element(*)*

id#2

declare  function fn:id($arg as xs:string*, $node as node()) as element(*)* external

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.

The one-argument form of this function is deterministic, context-dependent, and focus-dependent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

The function returns a sequence, in document order with duplicates eliminated, containing every element node E that satisfies all the following conditions:

E is in the target document. The target document is the document containing $node, or the document containing the context item (.) if the second argument is omitted. The behavior of the function if $node is omitted is exactly the same as if the context item had been passed as $node.

E has an ID value equal to one of the candidate IDREF values, where:

An element has an ID value equal to V if either or both of the following conditions are true:

The is-id property (See .) of the element node is true, and the typed value of the element node is equal to V under the rules of the eq operator using the Unicode codepoint collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

The element has an attribute node whose is-id property (See .) is true and whose typed value is equal to V under the rules of the eq operator using the Unicode code point collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

Each xs:string in $arg is parsed as if it were of type IDREFS, that is, each xs:string in $arg is treated as a whitespace-separated sequence of tokens, each acting as an IDREF. These tokens are then included in the list of candidate IDREFs. If any of the tokens is not a lexically valid IDREF (that is, if it is not lexically an xs:NCName), it is ignored. Formally, the candidate IDREF values are the strings in the sequence given by the expression:

for $s in $arg return fn:tokenize(fn:normalize-space($s), ' ')[. castable as xs:IDREF]

If several elements have the same ID value, then E is the one that is first in document order.

A dynamic error is raised if $node, or the context item if the second argument is absent, is a node in a tree whose root is not a document node.

The following errors may be raised when $node is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as xs:string
node as node()

Returns

element(*)*

idref#1

declare  function fn:idref($arg as xs:string*) as node()* external

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.

The one-argument form of this function is deterministic, context-dependent, and focus-dependent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

The function returns a sequence, in document order with duplicates eliminated, containing every element or attribute node $N that satisfies all the following conditions:

$N is in the target document. The target document is the document containing $node or the document containing the context item (.) if the second argument is omitted. The behavior of the function if $node is omitted is exactly the same as if the context item had been passed as $node.

$N has an IDREF value equal to one of the candidate ID values, where:

A node $N has an IDREF value equal to V if both of the following conditions are true:

The is-idrefs property (see ) of $N is true.

The sequence fn:tokenize(fn:normalize-space(fn:string($N)), ' ') contains a string that is equal to V under the rules of the eq operator using the Unicode code point collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

Each xs:string in $arg is parsed as if it were of lexically of type xs:ID. These xs:strings are then included in the list of candidate xs:IDs. If any of the strings in $arg is not a lexically valid xs:ID (that is, if it is not lexically an xs:NCName), it is ignored. More formally, the candidate ID values are the strings in the sequence:

$arg[. castable as xs:NCName]

A dynamic error is raised if $node, or the context item if the second argument is omitted, is a node in a tree whose root is not a document node.

The following errors may be raised when $node is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as xs:string

Returns

node()*

idref#2

declare  function fn:idref($arg as xs:string*, $node as node()) as node()* external

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.

The one-argument form of this function is deterministic, context-dependent, and focus-dependent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

The function returns a sequence, in document order with duplicates eliminated, containing every element or attribute node $N that satisfies all the following conditions:

$N is in the target document. The target document is the document containing $node or the document containing the context item (.) if the second argument is omitted. The behavior of the function if $node is omitted is exactly the same as if the context item had been passed as $node.

$N has an IDREF value equal to one of the candidate ID values, where:

A node $N has an IDREF value equal to V if both of the following conditions are true:

The is-idrefs property (see ) of $N is true.

The sequence fn:tokenize(fn:normalize-space(fn:string($N)), ' ') contains a string that is equal to V under the rules of the eq operator using the Unicode code point collation (http://www.w3.org/2005/xpath-functions/collation/codepoint).

Each xs:string in $arg is parsed as if it were of lexically of type xs:ID. These xs:strings are then included in the list of candidate xs:IDs. If any of the strings in $arg is not a lexically valid xs:ID (that is, if it is not lexically an xs:NCName), it is ignored. More formally, the candidate ID values are the strings in the sequence:

$arg[. castable as xs:NCName]

A dynamic error is raised if $node, or the context item if the second argument is omitted, is a node in a tree whose root is not a document node.

The following errors may be raised when $node is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as xs:string
node as node()

Returns

node()*

implicit-timezone#0

declare  function fn:implicit-timezone() as xs:dayTimeDuration external

Returns the value of the implicit timezone property from the dynamic context.

This function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

Returns the value of the implicit timezone property from the dynamic context. Components of the dynamic context are discussed in .

Parameters

Returns

xs:dayTimeDuration

in-scope-prefixes#1

declare  function fn:in-scope-prefixes($element as element(*)) as xs:string* external

Returns the prefixes of the in-scope namespaces for an element node.

This function is deterministic, context-independent, and focus-independent.

The function returns a sequence of strings representing the prefixes of the in-scope namespaces for $element.

For namespace bindings that have a prefix, the function returns the prefix as an xs:NCName. For the default namespace, which has no prefix, it returns the zero-length string.

The result sequence contains no duplicates.

The ordering of the result sequence is implementation-dependent.

Parameters

element as element(*)

Returns

xs:string*

index-of#2

declare  function fn:index-of($seq as xs:anyAtomicType*, $search as xs:anyAtomicType) as xs:integer* external

Returns a sequence of positive integers giving the positions within the sequence $seq of items that are equal to $search.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

The function returns a sequence of positive integers giving the positions within the sequence $seq of items that are equal to $search.

The collation used by this function is determined according to the rules in . This collation is used when string comparison is required.

The items in the sequence $seq are compared with $search under the rules for the eq operator. Values of type xs:untypedAtomic are compared as if they were of type xs:string. Values that cannot be compared, because the eq operator is not defined for their types, are considered to be distinct. If an item compares equal, then the position of that item in the sequence $seq is included in the result.

The first item in a sequence is at position 1, not position 0.

The result sequence is in ascending numeric order.

If the value of $seq is the empty sequence, or if no item in $seq matches $search, then the function returns the empty sequence.

No error occurs if non-comparable values are encountered. So when comparing two atomic values, the effective boolean value of fn:index-of($a, $b) is true if $a and $b are equal, false if they are not equal or not comparable.

Parameters

seq as xs:anyAtomicType
search as xs:anyAtomicType

Returns

xs:integer*

index-of#3

declare  function fn:index-of($seq as xs:anyAtomicType*, $search as xs:anyAtomicType, $collation as xs:string) as xs:integer* external

Returns a sequence of positive integers giving the positions within the sequence $seq of items that are equal to $search.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

The function returns a sequence of positive integers giving the positions within the sequence $seq of items that are equal to $search.

The collation used by this function is determined according to the rules in . This collation is used when string comparison is required.

The items in the sequence $seq are compared with $search under the rules for the eq operator. Values of type xs:untypedAtomic are compared as if they were of type xs:string. Values that cannot be compared, because the eq operator is not defined for their types, are considered to be distinct. If an item compares equal, then the position of that item in the sequence $seq is included in the result.

The first item in a sequence is at position 1, not position 0.

The result sequence is in ascending numeric order.

If the value of $seq is the empty sequence, or if no item in $seq matches $search, then the function returns the empty sequence.

No error occurs if non-comparable values are encountered. So when comparing two atomic values, the effective boolean value of fn:index-of($a, $b) is true if $a and $b are equal, false if they are not equal or not comparable.

Parameters

seq as xs:anyAtomicType
search as xs:anyAtomicType
collation as xs:string

Returns

xs:integer*

innermost#1

declare  function fn:innermost($nodes as node()*) as node()* external

Returns every node within the input sequence that is not an ancestor of another member of the input sequence; the nodes are returned in document order with duplicates eliminated.

This function is deterministic, context-independent, and focus-independent.

The effect of the function call fn:innermost($nodes) is defined to be equivalent to the result of the expression $nodes except $nodes/ancestor::node().

That is, the function takes as input a sequence of nodes, and returns every node within the sequence that is not an ancestor of another node within the sequence; the nodes are returned in document order with duplicates eliminated.

If the source document contains nested sections represented by div elements, the expression innermost(//div) returns those div elements that do not contain further div elements.

Parameters

nodes as node()

Returns

node()*

insert-before#3

declare  function fn:insert-before($target as item()*, $position as xs:integer, $inserts as item()*) as item()* external

Returns a sequence constructed by inserting an item or a sequence of items at a given position within an existing sequence.

This function is deterministic, context-independent, and focus-independent.

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

For detailed type semantics, see [Formal Semantics].

If $target is the empty sequence, $inserts is returned. If $inserts is the empty sequence, $target is returned.

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.

The value of $target is not affected by the sequence construction.

Parameters

target as item()
position as xs:integer
inserts as item()

Returns

item()*

iri-to-uri#1

declare  function fn:iri-to-uri($iri as xs:string?) as xs:string external

Converts a string containing an IRI into a URI according to the rules of .

This function is deterministic, context-independent, and focus-independent.

If $iri is the empty sequence, the function returns the zero-length string.

Otherwise, the function converts the value of $iri into a URI according to the rules given in Section 3.1 of by percent-encoding characters that are allowed in an IRI but not in a URI. 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 before the conversion is performed.

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

The function is idempotent but not invertible. Both the inputs My Documents and My%20Documents will be converted to the output My%20Documents.

This function does not check whether $iri is a valid IRI. It treats it as an string and operates on the characters in the string.

The following printable ASCII characters are invalid in an IRI: "<", ">", " (double quote), space, "{", "}", "|", "\", "^", and "`". Since these characters should not appear in an IRI, if they do appear in $iri they will be percent-encoded. In addition, characters outside the range x20-x7E will be percent-encoded because they are invalid in a URI.

Since this function does not escape the PERCENT SIGN "%" and this character is not allowed in data within a URI, users wishing to convert character strings (such as file names) that include "%" to a URI should manually escape "%" by replacing it with "%25".

Parameters

iri as xs:string

Returns

xs:string

lang#1

declare  function fn:lang($testlang as xs:string?) as xs:boolean external

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 one-argument form of this function is deterministic, context-dependent, and focus-dependent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

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.

If $testlang is the empty sequence it is interpreted as the zero-length string.

The relevant xml:lang attribute is determined by the value of the XPath expression:

(ancestor-or-self::*/@xml:lang)[last()]

If this expression returns an empty sequence, the function returns false.

Otherwise, the function returns true if and only if, based on a caseless default match as specified in section 3.13 of , either:

$testlang is equal to the string-value of the relevant xml:lang attribute, or

$testlang is equal to some substring of the string-value of the relevant xml:lang attribute that starts at the start of the string-value and ends immediately before a hyphen, "-" (the character "-" is HYPHEN-MINUS, #x002D).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

testlang as xs:string

Returns

xs:boolean

lang#2

declare  function fn:lang($testlang as xs:string?, $node as node()) as xs:boolean external

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 one-argument form of this function is deterministic, context-dependent, and focus-dependent.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

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.

If $testlang is the empty sequence it is interpreted as the zero-length string.

The relevant xml:lang attribute is determined by the value of the XPath expression:

(ancestor-or-self::*/@xml:lang)[last()]

If this expression returns an empty sequence, the function returns false.

Otherwise, the function returns true if and only if, based on a caseless default match as specified in section 3.13 of , either:

$testlang is equal to the string-value of the relevant xml:lang attribute, or

$testlang is equal to some substring of the string-value of the relevant xml:lang attribute that starts at the start of the string-value and ends immediately before a hyphen, "-" (the character "-" is HYPHEN-MINUS, #x002D).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

testlang as xs:string
node as node()

Returns

xs:boolean

last#0

declare  function fn:last() as xs:integer external

Returns the context size from the dynamic context.

This function is deterministic, context-dependent, and focus-dependent.

Returns the context size from the dynamic context. (See .)

A dynamic error is raised if the context item is absent.

Parameters

Returns

xs:integer

local-name-from-QName#1

declare  function fn:local-name-from-QName($arg as xs:QName?) as xs:NCName? external

Returns the local part of the supplied QName.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence the function returns the empty sequence.

Otherwise, the function returns an xs:NCName representing the local part of $arg.

The expression fn:local-name-from-QName(fn:QName("http://www.example.com/example", "person")) returns "person".

Parameters

arg as xs:QName

Returns

xs:NCName?

local-name#0

declare  function fn:local-name() as xs:string external

Returns the local part of the name of $arg as an xs:string that is either the zero-length string, or has the lexical form of an xs:NCName.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If the argument is supplied and is the empty sequence, the function returns the zero-length string.

If the node identified by $arg has no name (that is, if it is a document node, a comment, a text node, or a namespace node having no name), the function returns the zero-length string.

Otherwise, the function returns the local part of the expanded-QName of the node identified by $arg, as determined by the dm:node-name accessor defined in ). This will be an xs:string whose lexical form is an xs:NCName.

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:string

local-name#1

declare  function fn:local-name($arg as node()?) as xs:string external

Returns the local part of the name of $arg as an xs:string that is either the zero-length string, or has the lexical form of an xs:NCName.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If the argument is supplied and is the empty sequence, the function returns the zero-length string.

If the node identified by $arg has no name (that is, if it is a document node, a comment, a text node, or a namespace node having no name), the function returns the zero-length string.

Otherwise, the function returns the local part of the expanded-QName of the node identified by $arg, as determined by the dm:node-name accessor defined in ). This will be an xs:string whose lexical form is an xs:NCName.

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

xs:string

lower-case#1

declare  function fn:lower-case($arg as xs:string?) as xs:string external

Converts a string to lower case.

This function is deterministic, context-independent, and focus-independent.

If the value of $arg is the empty sequence, the zero-length string is returned.

Otherwise, the function 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 . 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.

Case mappings may change the length of a string. In general, the fn:upper-case and fn:lower-case functions are not inverses of each other: fn:lower-case(fn:upper-case($arg)) is not guaranteed to return $arg, nor is fn:upper-case(fn:lower-case($arg)). The Latin small letter dotless i (as used in Turkish) is perhaps the most prominent lower-case letter which will not round-trip. The Latin capital letter i with dot above is the most prominent upper-case letter which will not round trip; there are others, such as Latin capital letter Sharp S (#1E9E) which is introduced in Unicode 5.1.

These functions may not always be linguistically appropriate (e.g. Turkish i without dot) or appropriate for the application (e.g. titlecase). In cases such as Turkish, a simple translation should be used first.

Because the function is not sensitive to locale, results will not always match user expectations. In Quebec, for example, the standard uppercase equivalent of "è" is "È", while in metropolitan France it is more commonly "E"; only one of these is supported by the functions as defined.

Many characters of class Ll lack uppercase equivalents in the Unicode case mapping tables; many characters of class Lu lack lowercase equivalents.

Parameters

arg as xs:string

Returns

xs:string

matches#2

declare  function fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean external

Returns true if the supplied string matches a given regular expression.

This function is deterministic, context-independent, and focus-independent.

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 .

If $input is the empty sequence, it is interpreted as the zero-length string.

The function returns true if $input or some substring of $input matches the regular expression supplied as $pattern. Otherwise, the function returns false. The matching rules are influenced by the value of $flags if present.

A dynamic error is raised if the value of $pattern is invalid according to the rules described in .

A dynamic error is raised if the value of $flags is invalid according to the rules described in .

Parameters

input as xs:string
pattern as xs:string

Returns

xs:boolean

matches#3

declare  function fn:matches($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:boolean external

Returns true if the supplied string matches a given regular expression.

This function is deterministic, context-independent, and focus-independent.

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 .

If $input is the empty sequence, it is interpreted as the zero-length string.

The function returns true if $input or some substring of $input matches the regular expression supplied as $pattern. Otherwise, the function returns false. The matching rules are influenced by the value of $flags if present.

A dynamic error is raised if the value of $pattern is invalid according to the rules described in .

A dynamic error is raised if the value of $flags is invalid according to the rules described in .

Parameters

input as xs:string
pattern as xs:string
flags as xs:string

Returns

xs:boolean

max#1

declare  function fn:max($arg as xs:anyAtomicType*) as xs:anyAtomicType? external

Returns a value that is equal to the highest value appearing in the input sequence.

The zero-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

The following rules are applied to the input sequence $arg:

Values of type xs:untypedAtomic in $arg are cast to xs:double.

Numeric and xs:anyURI values are converted to the least common type reachable by a combination of type promotion and subtype substitution. See and .

The items in the resulting sequence may be reordered in an arbitrary order. The resulting sequence is referred to below as the converted sequence. The function returns an item from the converted sequence rather than the input sequence.

If the converted sequence is empty, the function returns the empty sequence.

All items in the converted sequence must be derived from a single base type for which the le operator is defined. In addition, the values in the sequence must have a total order. If date/time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for the purpose of comparison. Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.

If the converted sequence contains the value NaN, the value NaN is returned.

If the items in the converted sequence are of type xs:string or types derived by restriction from xs:string, then the determination of the item with the smallest value is made according to the collation that is used. If the type of the items in the converted sequence is not xs:string and $collation is specified, the collation is ignored.

The collation used by this function is determined according to the rules in .

The function returns the result of the expression:

if (every $v in $c satisfies $c[1] ge $v) then $c[1] else fn:max(fn:subsequence($c, 2))

evaluated with $collation as the default collation if specified, and with $c as the converted sequence.

For detailed type semantics, see [Formal Semantics].

A type error is raised if the input sequence contains items of incompatible types, as described above.

Parameters

arg as xs:anyAtomicType

Returns

xs:anyAtomicType?

max#2

declare  function fn:max($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType? external

Returns a value that is equal to the highest value appearing in the input sequence.

The zero-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

The following rules are applied to the input sequence $arg:

Values of type xs:untypedAtomic in $arg are cast to xs:double.

Numeric and xs:anyURI values are converted to the least common type reachable by a combination of type promotion and subtype substitution. See and .

The items in the resulting sequence may be reordered in an arbitrary order. The resulting sequence is referred to below as the converted sequence. The function returns an item from the converted sequence rather than the input sequence.

If the converted sequence is empty, the function returns the empty sequence.

All items in the converted sequence must be derived from a single base type for which the le operator is defined. In addition, the values in the sequence must have a total order. If date/time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for the purpose of comparison. Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.

If the converted sequence contains the value NaN, the value NaN is returned.

If the items in the converted sequence are of type xs:string or types derived by restriction from xs:string, then the determination of the item with the smallest value is made according to the collation that is used. If the type of the items in the converted sequence is not xs:string and $collation is specified, the collation is ignored.

The collation used by this function is determined according to the rules in .

The function returns the result of the expression:

if (every $v in $c satisfies $c[1] ge $v) then $c[1] else fn:max(fn:subsequence($c, 2))

evaluated with $collation as the default collation if specified, and with $c as the converted sequence.

For detailed type semantics, see [Formal Semantics].

A type error is raised if the input sequence contains items of incompatible types, as described above.

Parameters

arg as xs:anyAtomicType
collation as xs:string

Returns

xs:anyAtomicType?

min#1

declare  function fn:min($arg as xs:anyAtomicType*) as xs:anyAtomicType? external

Returns a value that is equal to the lowest value appearing in the input sequence.

The zero-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

The following rules are applied to the input sequence:

Values of type xs:untypedAtomic in $arg are cast to xs:double.

Numeric and xs:anyURI values are converted to the least common type reachable by a combination of type promotion and subtype substitution. See and .

The items in the resulting sequence may be reordered in an arbitrary order. The resulting sequence is referred to below as the converted sequence. The function returns an item from the converted sequence rather than the input sequence.

If the converted sequence is empty, the empty sequence is returned.

All items in the converted sequence must be derived from a single base type for which the le operator is defined. In addition, the values in the sequence must have a total order. If date/time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for the purpose of comparison. Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.

If the converted sequence contains the value NaN, the value NaN is returned.

If the items in the converted sequence are of type xs:string or types derived by restriction from xs:string, then the determination of the item with the smallest value is made according to the collation that is used. If the type of the items in the converted sequence is not xs:string and $collation is specified, the collation is ignored.

The collation used by this function is determined according to the rules in .

The function returns the result of the expression:

if (every $v in $c satisfies $c[1] le $v) then $c[1] else fn:min(fn:subsequence($c, 2))

evaluated with $collation as the default collation if specified, and with $c as the converted sequence.

For detailed type semantics, see [Formal Semantics].

A type error is raised if the input sequence contains items of incompatible types, as described above.

Parameters

arg as xs:anyAtomicType

Returns

xs:anyAtomicType?

min#2

declare  function fn:min($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType? external

Returns a value that is equal to the lowest value appearing in the input sequence.

The zero-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and implicit timezone.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri, and implicit timezone.

The following rules are applied to the input sequence:

Values of type xs:untypedAtomic in $arg are cast to xs:double.

Numeric and xs:anyURI values are converted to the least common type reachable by a combination of type promotion and subtype substitution. See and .

The items in the resulting sequence may be reordered in an arbitrary order. The resulting sequence is referred to below as the converted sequence. The function returns an item from the converted sequence rather than the input sequence.

If the converted sequence is empty, the empty sequence is returned.

All items in the converted sequence must be derived from a single base type for which the le operator is defined. In addition, the values in the sequence must have a total order. If date/time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for the purpose of comparison. Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.

If the converted sequence contains the value NaN, the value NaN is returned.

If the items in the converted sequence are of type xs:string or types derived by restriction from xs:string, then the determination of the item with the smallest value is made according to the collation that is used. If the type of the items in the converted sequence is not xs:string and $collation is specified, the collation is ignored.

The collation used by this function is determined according to the rules in .

The function returns the result of the expression:

if (every $v in $c satisfies $c[1] le $v) then $c[1] else fn:min(fn:subsequence($c, 2))

evaluated with $collation as the default collation if specified, and with $c as the converted sequence.

For detailed type semantics, see [Formal Semantics].

A type error is raised if the input sequence contains items of incompatible types, as described above.

Parameters

arg as xs:anyAtomicType
collation as xs:string

Returns

xs:anyAtomicType?

minutes-from-dateTime#1

declare  function fn:minutes-from-dateTime($arg as xs:dateTime?) as xs:integer? external

Returns the minute component of an xs:dateTime.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:integer value between 0 and 59, both inclusive, representing the minute component in the local value of $arg.

The expression fn:minutes-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) returns 20.

The expression fn:minutes-from-dateTime(xs:dateTime("1999-05-31T13:30:00+05:30")) returns 30.

Parameters

arg as xs:dateTime

Returns

xs:integer?

minutes-from-duration#1

declare  function fn:minutes-from-duration($arg as xs:duration?) as xs:integer? external

Returns the number of minutes in a duration.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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 ) and then computing the minutes component as described in .

If $arg is a negative duration then the result will be negative..

If $arg is an xs:yearMonthDuration the function returns 0.

The expression fn:minutes-from-duration(xs:dayTimeDuration("P3DT10H")) returns 0.

The expression fn:minutes-from-duration(xs:dayTimeDuration("-P5DT12H30M")) returns -30.

Parameters

arg as xs:duration

Returns

xs:integer?

minutes-from-time#1

declare  function fn:minutes-from-time($arg as xs:time?) as xs:integer? external

Returns the minutes component of an xs:time.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:integer value between 0 and 59, both inclusive, representing the value of the minutes component in the local value of $arg.

The expression fn:minutes-from-time(xs:time("13:00:00Z")) returns 0.

Parameters

arg as xs:time

Returns

xs:integer?

month-from-date#1

declare  function fn:month-from-date($arg as xs:date?) as xs:integer? external

Returns the month component of an xs:date.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:integer between 1 and 12, both inclusive, representing the month component in the local value of $arg.

The expression fn:month-from-date(xs:date("1999-05-31-05:00")) returns 5.

The expression fn:month-from-date(xs:date("2000-01-01+05:00")) returns 1.

Parameters

arg as xs:date

Returns

xs:integer?

months-from-duration#1

declare  function fn:months-from-duration($arg as xs:duration?) as xs:integer? external

Returns the number of months in a duration.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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 ) and then computing the months component as described in .

If $arg is a negative duration then the result will be negative..

If $arg is an xs:dayTimeDuration the function returns 0.

The expression fn:months-from-duration(xs:yearMonthDuration("P20Y15M")) returns 3.

The expression fn:months-from-duration(xs:yearMonthDuration("-P20Y18M")) returns -6.

The expression fn:months-from-duration(xs:dayTimeDuration("-P2DT15H0M0S")) returns 0.

Parameters

arg as xs:duration

Returns

xs:integer?

name#0

declare  function fn:name() as xs:string external

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.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If the argument is supplied and is the empty sequence, the function returns the zero-length string.

If the node identified by $arg has no name (that is, if it is a document node, a comment, a text node, or a namespace node having no name), the function returns the zero-length string.

Otherwise, the function returns the value of the expression fn:string(fn:node-name($arg)).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:string

name#1

declare  function fn:name($arg as node()?) as xs:string external

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.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If the argument is supplied and is the empty sequence, the function returns the zero-length string.

If the node identified by $arg has no name (that is, if it is a document node, a comment, a text node, or a namespace node having no name), the function returns the zero-length string.

Otherwise, the function returns the value of the expression fn:string(fn:node-name($arg)).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

xs:string

namespace-uri-for-prefix#2

declare  function fn:namespace-uri-for-prefix($prefix as xs:string?, $element as element(*)) as xs:anyURI? external

Returns the namespace URI of one of the in-scope namespaces for $element, identified by its namespace prefix.

This function is deterministic, context-independent, and focus-independent.

If $element has an in-scope namespace whose namespace prefix is equal to $prefix, the function returns the namespace URI of that namespace.

If $element has no in-scope namespace whose namespace prefix is equal to $prefix, the function returns the empty sequence.

If $prefix is the zero-length string or the empty sequence, then if $element has a default namespace (that is, a namespace node with no name), the function returns the namespace URI of the default namespace. If $element has no default namespace, the function returns the empty sequence.

Prefixes are equal only if their Unicode codepoints match exactly.

let $e := <z:a xmlns="http://example.org/one" xmlns:z="http://example.org/two"> <b xmlns=""/> </z:a>

The expression fn:namespace-uri-for-prefix("z", $e) returns "http://example.org/two".

The expression fn:namespace-uri-for-prefix("", $e) returns "http://example.org/one".

The expression fn:namespace-uri-for-prefix((), $e) returns "http://example.org/one".

The expression fn:namespace-uri-for-prefix("xml", $e) returns "http://www.w3.org/XML/1998/namespace".

The expression fn:namespace-uri-for-prefix("xml", $e) returns "http://www.w3.org/XML/1998/namespace".

Parameters

prefix as xs:string
element as element(*)

Returns

xs:anyURI?

namespace-uri-from-QName#1

declare  function fn:namespace-uri-from-QName($arg as xs:QName?) as xs:anyURI? external

Returns the namespace URI part of the supplied QName.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence the function returns the empty sequence.

Otherwise, the function returns an xs:anyURI representing the namespace URI part of $arg.

If $arg is in no namespace, the function returns the zero-length xs:anyURI.

The expression fn:namespace-uri-from-QName(fn:QName("http://www.example.com/example", "person")) returns xs:anyURI("http://www.example.com/example").

Parameters

arg as xs:QName

Returns

xs:anyURI?

namespace-uri#0

declare  function fn:namespace-uri() as xs:anyURI external

Returns the namespace URI part of the name of $arg, as an xs:anyURI value.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context node (.). 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 node identified by $arg is neither an element nor an attribute node, or if it is an element or attribute node whose expanded-QName (as determined by the dm:node-name accessor in the ) is in no namespace, then the function returns the zero-length xs:anyURI value.

Otherwise, the result will be the namespace URI part of the expanded-QName of the node identified by $arg, as determined by the dm:node-name accessor defined in ), returned as an xs:anyURI value.

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:anyURI

namespace-uri#1

declare  function fn:namespace-uri($arg as node()?) as xs:anyURI external

Returns the namespace URI part of the name of $arg, as an xs:anyURI value.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context node (.). 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 node identified by $arg is neither an element nor an attribute node, or if it is an element or attribute node whose expanded-QName (as determined by the dm:node-name accessor in the ) is in no namespace, then the function returns the zero-length xs:anyURI value.

Otherwise, the result will be the namespace URI part of the expanded-QName of the node identified by $arg, as determined by the dm:node-name accessor defined in ), returned as an xs:anyURI value.

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

xs:anyURI

nilled#0

declare  function fn:nilled() as xs:boolean external

Returns true for an element that is nilled.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the function returns the result of the dm:nilled accessor as defined in (see ).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:boolean

nilled#1

declare  function fn:nilled($arg as node()?) as xs:boolean? external

Returns true for an element that is nilled.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the function returns the result of the dm:nilled accessor as defined in (see ).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

xs:boolean?

node-name#0

declare  function fn:node-name() as xs:QName? external

Returns the name of a node, as an xs:QName.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If $arg is the empty sequence, the empty sequence is returned.

Otherwise, the function returns the result of the dm:node-name accessor as defined in (see ).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

xs:QName?

node-name#1

declare  function fn:node-name($arg as node()?) as xs:QName? external

Returns the name of a node, as an xs:QName.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the argument is omitted, it defaults to the context 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.

If $arg is the empty sequence, the empty sequence is returned.

Otherwise, the function returns the result of the dm:node-name accessor as defined in (see ).

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

xs:QName?

normalize-space#0

declare  function fn:normalize-space() as xs:string external

Returns the value of $arg with leading and trailing whitespace removed, and sequences of internal whitespace reduced to a single space character.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the value of $arg is the empty sequence, the function returns the zero-length string.

The function returns a string constructed by stripping leading and trailing whitespace from the value of $arg, and replacing sequences of one or more adjacent whitespace characters with a single space, #x20.

The whitespace characters are defined in the metasymbol S (Production 3) of .

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 absent then a dynamic error is raised: .

Parameters

Returns

xs:string

normalize-space#1

declare  function fn:normalize-space($arg as xs:string?) as xs:string external

Returns the value of $arg with leading and trailing whitespace removed, and sequences of internal whitespace reduced to a single space character.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the value of $arg is the empty sequence, the function returns the zero-length string.

The function returns a string constructed by stripping leading and trailing whitespace from the value of $arg, and replacing sequences of one or more adjacent whitespace characters with a single space, #x20.

The whitespace characters are defined in the metasymbol S (Production 3) of .

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 absent then a dynamic error is raised: .

Parameters

arg as xs:string

Returns

xs:string

normalize-unicode#1

declare  function fn:normalize-unicode($arg as xs:string?) as xs:string external

Returns the value of $arg after applying Unicode normalization.

This function is deterministic, context-independent, and focus-independent.

If the value of $arg is the empty sequence, the function returns the zero-length string.

If the single-argument version of the function is used, the result is the same as calling the two-argument version with $normalizationForm set to the string "NFC".

Otherwise, the function returns the value of $arg normalized according to the rules of the normalization form identified by the value of $normalizationForm.

The effective value of $normalizationForm is the value of the expression fn:upper-case(fn:normalize-space($normalizationForm)).

See for a description of the normalization forms.

If the effective value of $normalizationForm is NFC, then the function returns the value of $arg converted to Unicode Normalization Form C (NFC).

If the effective value of $normalizationForm is NFD, then the function returns the value of $arg converted to Unicode Normalization Form D (NFD).

If the effective value of $normalizationForm is NFKC, then the function returns the value of $arg in Unicode Normalization Form KC (NFKC).

If the effective value of $normalizationForm is NFKD, then the function returns the value of $arg converted to Unicode Normalization Form KD (NFKD).

If the effective value of $normalizationForm is FULLY-NORMALIZED, then the function returns the value of $arg converted to fully normalized form.

If the effective value of $normalizationForm is the zero-length string, no normalization is performed and $arg is returned.

Normalization forms NFC, NFD, NFKC, and NFKD, and the algorithms to be used for converting a string to each of these forms, are defined in .

The motivation for normalization form FULLY-NORMALIZED is explained in . However, as that specification did not progress beyond working draft status, the normative specification is as follows:

A string is fully-normalized if (a) it is in normalization form NFC as defined in , and (b) it does not start with a composing character.

A composing character is a character that is one or both of the following:

the second character in the canonical decomposition mapping of some character that is not listed in the Composition Exclusion Table defined in ;

of non-zero canonical combining class (as defined in ).

A string is converted to FULLY-NORMALIZED form as follows:

if the first character in the string is a composing character, prepend a single space (x20);

convert the resulting string to normalization form NFC.

Conforming implementations must support normalization form "NFC" and may support normalization forms "NFD", "NFKC", "NFKD", and "FULLY-NORMALIZED". They may also support other normalization forms with implementation-defined semantics.

It is implementation-defined which version of Unicode (and therefore, of the normalization algorithms and their underlying data) is supported by the implementation. See for details of the stability policy regarding changes to the normalization rules in future versions of Unicode. If the input string contains codepoints that are unassigned in the relevant version of Unicode, or for which no normalization rules are defined, the fn:normalize-unicode function leaves such codepoints unchanged. If the implementation supports the requested normalization form then it must be able to handle every input string without raising an error.

A dynamic error is raised if the effective value of the $normalizationForm argument is not one of the values supported by the implementation.

Parameters

arg as xs:string

Returns

xs:string

normalize-unicode#2

declare  function fn:normalize-unicode($arg as xs:string?, $normalizationForm as xs:string) as xs:string external

Returns the value of $arg after applying Unicode normalization.

This function is deterministic, context-independent, and focus-independent.

If the value of $arg is the empty sequence, the function returns the zero-length string.

If the single-argument version of the function is used, the result is the same as calling the two-argument version with $normalizationForm set to the string "NFC".

Otherwise, the function returns the value of $arg normalized according to the rules of the normalization form identified by the value of $normalizationForm.

The effective value of $normalizationForm is the value of the expression fn:upper-case(fn:normalize-space($normalizationForm)).

See for a description of the normalization forms.

If the effective value of $normalizationForm is NFC, then the function returns the value of $arg converted to Unicode Normalization Form C (NFC).

If the effective value of $normalizationForm is NFD, then the function returns the value of $arg converted to Unicode Normalization Form D (NFD).

If the effective value of $normalizationForm is NFKC, then the function returns the value of $arg in Unicode Normalization Form KC (NFKC).

If the effective value of $normalizationForm is NFKD, then the function returns the value of $arg converted to Unicode Normalization Form KD (NFKD).

If the effective value of $normalizationForm is FULLY-NORMALIZED, then the function returns the value of $arg converted to fully normalized form.

If the effective value of $normalizationForm is the zero-length string, no normalization is performed and $arg is returned.

Normalization forms NFC, NFD, NFKC, and NFKD, and the algorithms to be used for converting a string to each of these forms, are defined in .

The motivation for normalization form FULLY-NORMALIZED is explained in . However, as that specification did not progress beyond working draft status, the normative specification is as follows:

A string is fully-normalized if (a) it is in normalization form NFC as defined in , and (b) it does not start with a composing character.

A composing character is a character that is one or both of the following:

the second character in the canonical decomposition mapping of some character that is not listed in the Composition Exclusion Table defined in ;

of non-zero canonical combining class (as defined in ).

A string is converted to FULLY-NORMALIZED form as follows:

if the first character in the string is a composing character, prepend a single space (x20);

convert the resulting string to normalization form NFC.

Conforming implementations must support normalization form "NFC" and may support normalization forms "NFD", "NFKC", "NFKD", and "FULLY-NORMALIZED". They may also support other normalization forms with implementation-defined semantics.

It is implementation-defined which version of Unicode (and therefore, of the normalization algorithms and their underlying data) is supported by the implementation. See for details of the stability policy regarding changes to the normalization rules in future versions of Unicode. If the input string contains codepoints that are unassigned in the relevant version of Unicode, or for which no normalization rules are defined, the fn:normalize-unicode function leaves such codepoints unchanged. If the implementation supports the requested normalization form then it must be able to handle every input string without raising an error.

A dynamic error is raised if the effective value of the $normalizationForm argument is not one of the values supported by the implementation.

Parameters

arg as xs:string
normalizationForm as xs:string

Returns

xs:string

not#1

declare  function fn:not($arg as item()*) as xs:boolean external

Returns true if the effective boolean value of $arg is false, or false if it is true.

This function is deterministic, context-independent, and focus-independent.

The value of $arg is first reduced to an effective boolean value by applying the fn:boolean() function. The function returns true if the effective boolean value is false, or false if the effective boolean value is true.

The expression fn:not(fn:true()) returns false().

The expression fn:not("false") returns false().

Parameters

arg as item()

Returns

xs:boolean

number#0

declare  function fn:number() as xs:double external

Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

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(.), as defined by the rules that follow.

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.

Otherwise, $arg , or the context item after atomization, is converted to an xs:double following the rules of . If the conversion to xs:double fails, the xs:double value NaN is returned.

A dynamic error is raised if $arg is omitted and the context item is absent.

As a consequence of the rules given above, a type error occurs if the context item cannot be atomized, or if the result of atomizing the context item is a sequence containing more than one atomic value.

Parameters

Returns

xs:double

number#1

declare  function fn:number($arg as xs:anyAtomicType?) as xs:double external

Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

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(.), as defined by the rules that follow.

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.

Otherwise, $arg , or the context item after atomization, is converted to an xs:double following the rules of . If the conversion to xs:double fails, the xs:double value NaN is returned.

A dynamic error is raised if $arg is omitted and the context item is absent.

As a consequence of the rules given above, a type error occurs if the context item cannot be atomized, or if the result of atomizing the context item is a sequence containing more than one atomic value.

Parameters

arg as xs:anyAtomicType

Returns

xs:double

one-or-more#1

declare  function fn:one-or-more($arg as item()*) as item()+ external

Returns $arg if it contains one or more items. Otherwise, raises an error.

This function is deterministic, context-independent, and focus-independent.

Except in error cases, the function returns $arg unchanged.

For detailed type semantics, see [Formal Semantics].

A dynamic error is raised if $arg is an empty sequence.

Parameters

arg as item()

Returns

item()+

outermost#1

declare  function fn:outermost($nodes as node()*) as node()* external

Returns every node within the input sequence that has no ancestor that is itself a member of the input sequence; the nodes are returned in document order with duplicates eliminated.

This function is deterministic, context-independent, and focus-independent.

The effect of the function call fn:outermost($nodes) is defined to be equivalent to the result of the expression $nodes[not(ancestor::node() intersect $nodes)]/..

That is, the function takes as input a sequence of nodes, and returns every node within the sequence that does not have another node within the sequence as an ancestor; the nodes are returned in document order with duplicates eliminated.

The formulation $nodes except $nodes/descendant::node() might appear to be simpler, but does not correctly account for attribute nodes, as these are not descendants of their parent element.

The motivation for the function was based on XSLT streaming use cases. There are cases where the streaming rules allow the construct outermost(//section) but do not allow //section; the function can therefore be useful in cases where it is known that sections will not be nested, as well as cases where the application actually wishes to process all sections except those that are nested within another.

Parameters

nodes as node()

Returns

node()*

parse-xml-fragment#1

declare  function fn:parse-xml-fragment($arg as xs:string?) as document(element(*,xs:untyped)) external

This function takes as input an XML external entity represented as a string, and returns the document node at the root of an XDM tree representing the parsed document fragment.

This function is nondeterministic, context-dependent, and focus-independent. It depends on static base uri.

If $arg is the empty sequence, the function returns the empty sequence.

The input must be a namespace-well-formed external general parsed entity. More specifically, it must be a string conforming to the production rule extParsedEnt in , it must contain no entity references other than references to predefined entities, and it must satisfy all the rules of for namespace-well-formed documents with the exception that the rule requiring it to be a well-formed document is replaced by the rule requiring it to be a well-formed external general parsed entity.

The string is parsed to form a sequence of nodes which become children of the new document node, in the same way as the content of any element is converted into a sequence of children for the resulting element node.

Schema validation is not invoked, which means that the nodes in the returned document will all be untyped.

The precise process used to construct the XDM instance is . In particular, it is implementation-defined whether an XML 1.0 or XML 1.1 parser is used.

The Static Base URI from the static context of the fn:parse-xml-fragment function call is used as the base URI of the document node that is returned.

The document URI of the returned node is absent.

The function is not deterministic: that is, if the function is called twice with the same arguments, it is implementation-dependent whether the same node is returned on both occasions.

A dynamic error is raised if the content of $arg is not a well-formed external general parsed entity, if it contains entity references other than references to predefined entities, or if a document that incorporates this well-formed parsed entity would not be namespace-well-formed.

Parameters

arg as xs:string

Returns

document(element(*,xs:untyped))

parse-xml#1

declare  function fn:parse-xml($arg as xs:string?) as document(element(*,xs:untyped)) external

This function takes as input an XML document represented as a string, and returns the document node at the root of an XDM tree representing the parsed document.

This function is nondeterministic, context-dependent, and focus-independent. It depends on static base uri.

If $arg is the empty sequence, the function returns the empty sequence.

The precise process used to construct the XDM instance is . In particular, it is implementation-defined whether DTD and/or schema validation is invoked, and it is implementation-defined whether an XML 1.0 or XML 1.1 parser is used.

The Static Base URI property from the static context of the fn:parse-xml function call is used both as the base URI used by the XML parser to resolve relative entity references within the document, and as the base URI of the document node that is returned.

The document URI of the returned node is absent.

The function is not deterministic: that is, if the function is called twice with the same arguments, it is implementation-dependent whether the same node is returned on both occasions.

A dynamic error is raised if the content of $arg is not a well-formed and namespace-well-formed XML document.

A dynamic error is raised if DTD-based validation is carried out and the content of $arg is not valid against its DTD.

Parameters

arg as xs:string

Returns

document(element(*,xs:untyped))

parse-xml#2

declare  function fn:parse-xml($arg as xs:string?, $baseURI as xs:string) as document(element(*,xs:untyped)) external

This function takes as input an XML document represented as a string, and returns the document node at the root of an XDM tree representing the parsed document.

This function is nondeterministic, context-dependent, and focus-independent. It depends on static base uri.

If $arg is the empty sequence, the function returns the empty sequence.

The precise process used to construct the XDM instance is . In particular, it is implementation-defined whether DTD and/or schema validation is invoked, and it is implementation-defined whether an XML 1.0 or XML 1.1 parser is used.

The Static Base URI property from the static context of the fn:parse-xml function call is used both as the base URI used by the XML parser to resolve relative entity references within the document, and as the base URI of the document node that is returned.

The document URI of the returned node is absent.

The function is not deterministic: that is, if the function is called twice with the same arguments, it is implementation-dependent whether the same node is returned on both occasions.

A dynamic error is raised if the content of $arg is not a well-formed and namespace-well-formed XML document.

A dynamic error is raised if DTD-based validation is carried out and the content of $arg is not valid against its DTD.

Parameters

arg as xs:string
baseURI as xs:string

Returns

document(element(*,xs:untyped))

position#0

declare  function fn:position() as xs:integer external

Returns the context position from the dynamic context.

This function is deterministic, context-dependent, and focus-dependent.

Returns the context position from the dynamic context. (See .)

A dynamic error is raised if the context item is absent.

Parameters

Returns

xs:integer

prefix-from-QName#1

declare  function fn:prefix-from-QName($arg as xs:QName?) as xs:NCName? external

Returns the prefix component of the supplied QName.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence the function returns the empty sequence.

If $arg has no prefix component the function returns the empty sequence.

Otherwise, the function returns an xs:NCName representing the prefix component of $arg.

Parameters

arg as xs:QName

Returns

xs:NCName?

remove#2

declare  function fn:remove($target as item()*, $position as xs:integer) as item()* external

Returns a new sequence containing all the items of $target except the item at position $position.

This function is deterministic, context-independent, and focus-independent.

The function returns a sequence consisting of all items of $target whose index is less than $position, followed by all items of $target whose index is greater than $position.

For detailed type semantics, see [Formal Semantics].

If $position is less than 1 or greater than the number of items in $target, $target is returned.

If $target is the empty sequence, the empty sequence is returned.

Parameters

target as item()
position as xs:integer

Returns

item()*

replace#3

declare  function fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string) as xs:string external

Returns a string produced from the input string by replacing any substrings that match a given regular expression with a supplied replacement string.

This function is deterministic, context-independent, and focus-independent.

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 .

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.

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.

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.

If the q flag is present, the replacement string is used as is.

Otherwise, 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.

More specifically, the rules are as follows, where S is the number of parenthesized sub-expressions in the regular expression, and N is the decimal number formed by taking all the digits that consecutively follow the $ character:

If N=0, then the variable is replaced by the substring matched by the regular expression as a whole.

If 1<=N<=S, then the variable is replaced by the substring captured by the Nth parenthesized sub-expression. If the Nth parenthesized sub-expression was not matched, then the variable is replaced by the zero-length string.

If S<N<=9, then the variable is replaced by the zero-length string.

Otherwise (if N>S and N>9), the last digit of N is taken to be a literal character to be included "as is" in the replacement string, and the rules are reapplied using the number N formed by stripping off this last digit.

For example, if the replacement string is $23 and there are 5 substrings, the result contains the value of the substring that matches the second sub-expression, followed by the digit 3 .

Unless the q flag is used, a literal $ character within the replacement string must be written as \$, and a literal \ character must be written as \\.

If two alternatives within the pattern both match at the same position in the $input, then the match that is chosen is the one matched by the first alternative. For example:

fn:replace("abcd", "(ab)|(a)", "[1=$1][2=$2]") returns "[1=ab][2=]cd"

A dynamic error is raised if the value of $pattern is invalid according to the rules described in section .

A dynamic error is raised if the value of $flags is invalid according to the rules described in section .

A dynamic error is raised if the pattern matches a zero-length string, that is, if the expression fn:matches("", $pattern, $flags) returns true. It is not an error, however, if a captured substring is zero-length.

A dynamic error is raised if the value of $replacement contains a "$" character that is not immediately followed by a digit 0-9 and not immediately preceded by a "\".

A dynamic error is raised if the value of $replacement contains a "\" character that is not part of a "\\" pair, unless it is immediately followed by a "$" character.

Parameters

input as xs:string
pattern as xs:string
replacement as xs:string

Returns

xs:string

replace#4

declare  function fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string, $flags as xs:string) as xs:string external

Returns a string produced from the input string by replacing any substrings that match a given regular expression with a supplied replacement string.

This function is deterministic, context-independent, and focus-independent.

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 .

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.

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.

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.

If the q flag is present, the replacement string is used as is.

Otherwise, 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.

More specifically, the rules are as follows, where S is the number of parenthesized sub-expressions in the regular expression, and N is the decimal number formed by taking all the digits that consecutively follow the $ character:

If N=0, then the variable is replaced by the substring matched by the regular expression as a whole.

If 1<=N<=S, then the variable is replaced by the substring captured by the Nth parenthesized sub-expression. If the Nth parenthesized sub-expression was not matched, then the variable is replaced by the zero-length string.

If S<N<=9, then the variable is replaced by the zero-length string.

Otherwise (if N>S and N>9), the last digit of N is taken to be a literal character to be included "as is" in the replacement string, and the rules are reapplied using the number N formed by stripping off this last digit.

For example, if the replacement string is $23 and there are 5 substrings, the result contains the value of the substring that matches the second sub-expression, followed by the digit 3 .

Unless the q flag is used, a literal $ character within the replacement string must be written as \$, and a literal \ character must be written as \\.

If two alternatives within the pattern both match at the same position in the $input, then the match that is chosen is the one matched by the first alternative. For example:

fn:replace("abcd", "(ab)|(a)", "[1=$1][2=$2]") returns "[1=ab][2=]cd"

A dynamic error is raised if the value of $pattern is invalid according to the rules described in section .

A dynamic error is raised if the value of $flags is invalid according to the rules described in section .

A dynamic error is raised if the pattern matches a zero-length string, that is, if the expression fn:matches("", $pattern, $flags) returns true. It is not an error, however, if a captured substring is zero-length.

A dynamic error is raised if the value of $replacement contains a "$" character that is not immediately followed by a digit 0-9 and not immediately preceded by a "\".

A dynamic error is raised if the value of $replacement contains a "\" character that is not part of a "\\" pair, unless it is immediately followed by a "$" character.

Parameters

input as xs:string
pattern as xs:string
replacement as xs:string
flags as xs:string

Returns

xs:string

resolve-QName#2

declare  function fn:resolve-QName($qname as xs:string?, $element as element(*)) as xs:QName? external

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.

This function is deterministic, context-independent, and focus-independent.

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

A dynamic error is raised if $qname does not have the correct lexical form for an instance of xs:QName.

A dynamic error is raised if $qname has a prefix and there is no namespace binding for $element that matches this prefix.

Parameters

qname as xs:string
element as element(*)

Returns

xs:QName?

resolve-uri#1

declare  function fn:resolve-uri($relative as xs:string?) as xs:anyURI? external

Resolves a relative IRI reference against an absolute IRI.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

If the second argument is absent, the effect is the same as calling the two-argument function with the value of fn:static-base-uri() as the second argument.

The function is defined to operate on IRI references as defined in , and the implementation must permit all arguments that are valid according to that specification. In addition, the implementation may accept some or all strings that conform to the rules for (absolute or relative) Legacy Extended IRI references as defined in . For the purposes of this section, the terms IRI and IRI reference include these extensions, insofar as the implementation chooses to support them.

If $relative is the empty sequence, the function returns the empty sequence.

If $relative is an absolute IRI (as defined above), then it is returned unchanged.

Otherwise, the function resolves the relative IRI reference $relative against the base IRI $base using the algorithm defined in , adapted by treating any character that would not be valid in an RFC3986 URI or relative reference in the same way that RFC3986 treats unreserved characters. No percent-encoding takes place.

The first form of this function resolves $relative against the value of the base-uri property from the static context. A dynamic error is raised if the base-uri property is not initialized in the static context.

A dynamic error is raised if $relative is not a valid IRI according to the rules of RFC3987, extended with an implementation-defined subset of the extensions permitted in LEIRI, or if it is not a suitable relative reference to use as input to the RFC3986 resolution algorithm extended to handle additional unreserved characters.

A dynamic error is raised if $base is not a valid IRI according to the rules of RFC3987, extended with an implementation-defined subset of the extensions permitted in LEIRI, or if it is not a suitable IRI to use as input to the chosen resolution algorithm (for example, if it is a relative IRI reference, if it is a non-hierarchic URI, or if it contains a fragment identifier).

A dynamic error is raised if the chosen resolution algorithm fails for any other reason.

Parameters

relative as xs:string

Returns

xs:anyURI?

resolve-uri#2

declare  function fn:resolve-uri($relative as xs:string?, $base as xs:string) as xs:anyURI? external

Resolves a relative IRI reference against an absolute IRI.

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

If the second argument is absent, the effect is the same as calling the two-argument function with the value of fn:static-base-uri() as the second argument.

The function is defined to operate on IRI references as defined in , and the implementation must permit all arguments that are valid according to that specification. In addition, the implementation may accept some or all strings that conform to the rules for (absolute or relative) Legacy Extended IRI references as defined in . For the purposes of this section, the terms IRI and IRI reference include these extensions, insofar as the implementation chooses to support them.

If $relative is the empty sequence, the function returns the empty sequence.

If $relative is an absolute IRI (as defined above), then it is returned unchanged.

Otherwise, the function resolves the relative IRI reference $relative against the base IRI $base using the algorithm defined in , adapted by treating any character that would not be valid in an RFC3986 URI or relative reference in the same way that RFC3986 treats unreserved characters. No percent-encoding takes place.

The first form of this function resolves $relative against the value of the base-uri property from the static context. A dynamic error is raised if the base-uri property is not initialized in the static context.

A dynamic error is raised if $relative is not a valid IRI according to the rules of RFC3987, extended with an implementation-defined subset of the extensions permitted in LEIRI, or if it is not a suitable relative reference to use as input to the RFC3986 resolution algorithm extended to handle additional unreserved characters.

A dynamic error is raised if $base is not a valid IRI according to the rules of RFC3987, extended with an implementation-defined subset of the extensions permitted in LEIRI, or if it is not a suitable IRI to use as input to the chosen resolution algorithm (for example, if it is a relative IRI reference, if it is a non-hierarchic URI, or if it contains a fragment identifier).

A dynamic error is raised if the chosen resolution algorithm fails for any other reason.

Parameters

relative as xs:string
base as xs:string

Returns

xs:anyURI?

reverse#1

declare  function fn:reverse($arg as item()*) as item()* external

Reverses the order of items in a sequence.

This function is deterministic, context-independent, and focus-independent.

The function returns a sequence containing the items in $arg in reverse order.

For detailed type semantics, see [Formal Semantics].

If $arg is the empty sequence, the empty sequence is returned.

Parameters

arg as item()

Returns

item()*

root#0

declare  function fn:root() as node() external

Returns the root of the tree to which $arg belongs. This will usually, but not necessarily, be a document node.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the function is called without an argument, the context 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 function returns the value of the expression ($arg/ancestor-or-self::node())[1].

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

Returns

node()

root#1

declare  function fn:root($arg as node()?) as node()? external

Returns the root of the tree to which $arg belongs. This will usually, but not necessarily, be a document node.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

If the function is called without an argument, the context 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 function returns the value of the expression ($arg/ancestor-or-self::node())[1].

The following errors may be raised when $arg is omitted:

  • If the context item is absent, dynamic error

  • If the context item is not a node, type error .

Parameters

arg as node()

Returns

node()?

round-half-to-even#1

declare  function fn:round-half-to-even($arg as numeric?) as numeric? external

Rounds a value to a specified number of decimal places, rounding to make the last digit even if two such values are equally near.

This function is deterministic, context-independent, and focus-independent.

General rules: see .

The function returns 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 using an implementation of xs:decimal that imposes no limits on the number of digits that can be represented. 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.

For detailed type semantics, see [Formal Semantics].

This function is typically used in financial applications where the argument is of type xs:decimal. For arguments of type xs:float and xs:double the results may be counter-intuitive. For example, consider round-half-to-even(xs:float(150.015), 2). The result is not 150.02 as might be expected, but 150.01. This is because the conversion of the xs:float value represented by the literal 150.015 to an xs:decimal produces the xs:decimal value 150.014999389..., which is closer to 150.01 than to 150.02.

Parameters

arg as numeric

Returns

numeric?

round-half-to-even#2

declare  function fn:round-half-to-even($arg as numeric?, $precision as xs:integer) as numeric? external

Rounds a value to a specified number of decimal places, rounding to make the last digit even if two such values are equally near.

This function is deterministic, context-independent, and focus-independent.

General rules: see .

The function returns 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 using an implementation of xs:decimal that imposes no limits on the number of digits that can be represented. 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.

For detailed type semantics, see [Formal Semantics].

This function is typically used in financial applications where the argument is of type xs:decimal. For arguments of type xs:float and xs:double the results may be counter-intuitive. For example, consider round-half-to-even(xs:float(150.015), 2). The result is not 150.02 as might be expected, but 150.01. This is because the conversion of the xs:float value represented by the literal 150.015 to an xs:decimal produces the xs:decimal value 150.014999389..., which is closer to 150.01 than to 150.02.

Parameters

arg as numeric
precision as xs:integer

Returns

numeric?

round#1

declare  function fn:round($arg as numeric?) as numeric? external

Rounds a value to a specified number of decimal places, rounding upwards if two such values are equally near.

This function is deterministic, context-independent, and focus-independent.

General rules: see .

The function returns 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 (for example, if the fractional part in $arg is exactly .5), the function returns the one that is closest to positive infinity.

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 single-argument version of this function produces the same result as the two-argument version with $precision=0 (that is, it rounds to a whole number).

When $arg is of type xs:float and xs:double:

If $arg is NaN, positive or negative zero, or positive or negative infinity, then the result is the same as the argument.

For other values, the argument is cast to xs:decimal using an implementation of xs:decimal that imposes no limits on the number of digits that can be represented. 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 $arg.

For detailed type semantics, see [Formal Semantics].

This function is typically used with a non-zero $precision in financial applications where the argument is of type xs:decimal. For arguments of type xs:float and xs:double the results may be counter-intuitive. For example, consider round(35.425e0, 2). The result is not 35.43, as might be expected, but 35.42. This is because the xs:double written as 35.425e0 has an exact value equal to 35.42499999999..., which is closer to 35.42 than to 35.43.

Parameters

arg as numeric

Returns

numeric?

round#2

declare  function fn:round($arg as numeric?, $precision as xs:integer) as numeric? external

Rounds a value to a specified number of decimal places, rounding upwards if two such values are equally near.

This function is deterministic, context-independent, and focus-independent.

General rules: see .

The function returns 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 (for example, if the fractional part in $arg is exactly .5), the function returns the one that is closest to positive infinity.

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 single-argument version of this function produces the same result as the two-argument version with $precision=0 (that is, it rounds to a whole number).

When $arg is of type xs:float and xs:double:

If $arg is NaN, positive or negative zero, or positive or negative infinity, then the result is the same as the argument.

For other values, the argument is cast to xs:decimal using an implementation of xs:decimal that imposes no limits on the number of digits that can be represented. 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 $arg.

For detailed type semantics, see [Formal Semantics].

This function is typically used with a non-zero $precision in financial applications where the argument is of type xs:decimal. For arguments of type xs:float and xs:double the results may be counter-intuitive. For example, consider round(35.425e0, 2). The result is not 35.43, as might be expected, but 35.42. This is because the xs:double written as 35.425e0 has an exact value equal to 35.42499999999..., which is closer to 35.42 than to 35.43.

Parameters

arg as numeric
precision as xs:integer

Returns

numeric?

seconds-from-dateTime#1

declare  function fn:seconds-from-dateTime($arg as xs:dateTime?) as xs:decimal? external

Returns the seconds component of an xs:dateTime.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds in the local value of $arg.

The expression fn:seconds-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) returns 0.

Parameters

arg as xs:dateTime

Returns

xs:decimal?

seconds-from-duration#1

declare  function fn:seconds-from-duration($arg as xs:duration?) as xs:decimal? external

Returns the number of seconds in a duration.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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 ) and then computing the seconds component as described in .

If $arg is a negative duration then the result will be negative..

If $arg is an xs:yearMonthDuration the function returns 0.

The expression fn:seconds-from-duration(xs:dayTimeDuration("P3DT10H12.5S")) returns 12.5.

The expression fn:seconds-from-duration(xs:dayTimeDuration("-PT256S")) returns -16.0.

Parameters

arg as xs:duration

Returns

xs:decimal?

seconds-from-time#1

declare  function fn:seconds-from-time($arg as xs:time?) as xs:decimal? external

Returns the seconds component of an xs:time.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds in the local value of $arg.

The expression fn:seconds-from-time(xs:time("13:20:10.5")) returns 10.5.

Parameters

arg as xs:time

Returns

xs:decimal?

serialize#1

declare  function fn:serialize($arg as item()*) as xs:string external

This function serializes the supplied input sequence $arg as described in , returning the serialized representation of the sequence as a string.

This function is deterministic, context-independent, and focus-independent.

The value of $arg acts as the input sequence to the serialization process, which starts with sequence normalization.

The single-argument version of this function has the same effect as the two-argument version called with $params set to an empty sequence. This in turn is the same as the effect of passing an output:serialization-parameters element with no child elements.

The $params argument is used to identify a set of serialization parameters. These are supplied in the form of an output:serialization-parameters element, having the format described in .

The final stage of serialization, that is, encoding, is skipped. If the serializer does not allow this phase to be skipped, then the sequence of octets returned by the serializer is decoded into a string by reversing the character encoding performed in the final stage.

If the host language makes serialization an optional feature and the implementation does not support serialization, then a dynamic error is raised.

The serialization process will raise an error if $arg is an attribute or namespace node.

If any serialization error occurs, including the detection of an invalid value for a serialization parameter, this results in the fn:serialize call failing with a dynamic error.

Parameters

arg as item()

Returns

xs:string

serialize#2

declare  function fn:serialize($arg as item()*, $params as element(output:serialization-parameters)?) as xs:string external

This function serializes the supplied input sequence $arg as described in , returning the serialized representation of the sequence as a string.

This function is deterministic, context-independent, and focus-independent.

The value of $arg acts as the input sequence to the serialization process, which starts with sequence normalization.

The single-argument version of this function has the same effect as the two-argument version called with $params set to an empty sequence. This in turn is the same as the effect of passing an output:serialization-parameters element with no child elements.

The $params argument is used to identify a set of serialization parameters. These are supplied in the form of an output:serialization-parameters element, having the format described in .

The final stage of serialization, that is, encoding, is skipped. If the serializer does not allow this phase to be skipped, then the sequence of octets returned by the serializer is decoded into a string by reversing the character encoding performed in the final stage.

If the host language makes serialization an optional feature and the implementation does not support serialization, then a dynamic error is raised.

The serialization process will raise an error if $arg is an attribute or namespace node.

If any serialization error occurs, including the detection of an invalid value for a serialization parameter, this results in the fn:serialize call failing with a dynamic error.

Parameters

arg as item()
params as element(output:serialization-parameters)

Returns

xs:string

starts-with#2

declare  function fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a leading substring, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string

Returns

xs:boolean

starts-with#3

declare  function fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external

Returns true if the string $arg1 contains $arg2 as a leading substring, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string
collation as xs:string

Returns

xs:boolean

static-base-uri#0

declare  function fn:static-base-uri() as xs:anyURI? external

This function returns the value of the Static Base URI property from the static context.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The function returns the value of the Static Base URI property from the static context. If the property is absent, the empty sequence is returned.

Components of the static context are discussed in .

XQuery 3.0 and XSLT 3.0 give an implementation freedom to use different base URIs during the static analysis phase and the dynamic evaluation phase, that is, for compile-time and run-time resources respectively. In this situation, the fn:static-base-uri function should return a URI suitable for locating resources needed during dynamic evaluation.

Parameters

Returns

xs:anyURI?

string-join#1

declare  function fn:string-join($arg1 as xs:string*) as xs:string external

Returns a string created by concatenating the items in a sequence, with a defined separator between adjacent items.

This function is deterministic, context-independent, and focus-independent.

The effect of calling the single-argument version of this function is the same as calling the two-argument version with $arg2 set to a zero-length string.

The function returns an xs:string created by concatenating the items in the sequence $arg1, in order, using the value of $arg2 as a separator between adjacent items. 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 function returns the zero-length string.

Parameters

arg1 as xs:string

Returns

xs:string

string-join#2

declare  function fn:string-join($arg1 as xs:string*, $arg2 as xs:string) as xs:string external

Returns a string created by concatenating the items in a sequence, with a defined separator between adjacent items.

This function is deterministic, context-independent, and focus-independent.

The effect of calling the single-argument version of this function is the same as calling the two-argument version with $arg2 set to a zero-length string.

The function returns an xs:string created by concatenating the items in the sequence $arg1, in order, using the value of $arg2 as a separator between adjacent items. 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 function returns the zero-length string.

Parameters

arg1 as xs:string
arg2 as xs:string

Returns

xs:string

string-length#0

declare  function fn:string-length() as xs:integer external

Returns the number of characters in a string.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

The function returns an xs:integer equal to the length in characters of the value of $arg.

Calling the zero-argument version of the function is equivalent to calling fn:string-length(fn:string(.)).

If the value of $arg is the empty sequence, the function returns the xs:integer value zero (0).

If $arg is not specified and the context item is absent, a dynamic error is raised: .

Parameters

Returns

xs:integer

string-length#1

declare  function fn:string-length($arg as xs:string?) as xs:integer external

Returns the number of characters in a string.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

The function returns an xs:integer equal to the length in characters of the value of $arg.

Calling the zero-argument version of the function is equivalent to calling fn:string-length(fn:string(.)).

If the value of $arg is the empty sequence, the function returns the xs:integer value zero (0).

If $arg is not specified and the context item is absent, a dynamic error is raised: .

Parameters

arg as xs:string

Returns

xs:integer

string-to-codepoints#1

declare  function fn:string-to-codepoints($arg as xs:string?) as xs:integer* external

Returns the sequence of codepoints that constitute an xs:string value.

This function is deterministic, context-independent, and focus-independent.

The function returns a sequence of integers, each integer being the Unicode codepoints of the corresponding character in $arg.

If $arg is a zero-length string or the empty sequence, the function returns the empty sequence.

The expression fn:string-to-codepoints("Thérèse") returns (84, 104, 233, 114, 232, 115, 101).

Parameters

arg as xs:string

Returns

xs:integer*

string-to-codepoints#1

declare  function fn:string-to-codepoints($arg as xs:string?) as xs:integer* external

Returns the sequence of codepoints that constitute an xs:string value.

This function is deterministic, context-independent, and focus-independent.

The function returns a sequence of integers, each integer being the Unicode codepoints of the corresponding character in $arg.

If $arg is a zero-length string or the empty sequence, the function returns the empty sequence.

The expression fn:string-to-codepoints("Thérèse") returns (84, 104, 233, 114, 232, 115, 101).

Parameters

arg as xs:string

Returns

xs:integer*

string#0

declare  function fn:string() as xs:string external

Returns the value of $arg represented as an xs:string.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

In the zero-argument version of the function, $arg defaults to the context item. That is, calling fn:string() is equivalent to calling fn:string(.).

If $arg is the empty sequence, the function returns the zero-length string.

If $arg is a node, the function returns the string-value of the node, as obtained using the dm:string-value accessor defined in (see ).

If $arg is an atomic value, the function returns the result of the expression $arg cast as xs:string (see ).

A dynamic error is raised by the zero-argument version of the function if the context item is absent.

A type error is raised if $arg is a function item.

Parameters

Returns

xs:string

string#1

declare  function fn:string($arg as item()?) as xs:string external

Returns the value of $arg represented as an xs:string.

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.

The one-argument form of this function is deterministic, context-independent, and focus-independent.

In the zero-argument version of the function, $arg defaults to the context item. That is, calling fn:string() is equivalent to calling fn:string(.).

If $arg is the empty sequence, the function returns the zero-length string.

If $arg is a node, the function returns the string-value of the node, as obtained using the dm:string-value accessor defined in (see ).

If $arg is an atomic value, the function returns the result of the expression $arg cast as xs:string (see ).

A dynamic error is raised by the zero-argument version of the function if the context item is absent.

A type error is raised if $arg is a function item.

Parameters

arg as item()

Returns

xs:string

subsequence#2

declare  function fn:subsequence($sourceSeq as item()*, $startingLoc as xs:double) as item()* external

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.

This function is deterministic, context-independent, and focus-independent.

In the two-argument case, returns:

$sourceSeq[fn:round($startingLoc) le position()]

In the three-argument case, returns:

$sourceSeq[fn:round($startingLoc) le position() and position() lt fn:round($startingLoc) + fn:round($length)]

For detailed type semantics, see [Formal Semantics].

The first item of a sequence is located at position 1, not position 0.

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.

As an exception to the previous two notes, if $startingLoc is -INF and $length is +INF, then fn:round($startingLoc) + fn:round($length) is NaN; since position() lt NaN is always false, the result is an empty sequence.

The reason the function accepts arguments of type xs:double is that many computations on untyped data return an xs:double result; and the reason for the rounding rules is to compensate for any imprecision in these floating-point computations.

Parameters

sourceSeq as item()
startingLoc as xs:double

Returns

item()*

subsequence#3

declare  function fn:subsequence($sourceSeq as item()*, $startingLoc as xs:double, $length as xs:double) as item()* external

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.

This function is deterministic, context-independent, and focus-independent.

In the two-argument case, returns:

$sourceSeq[fn:round($startingLoc) le position()]

In the three-argument case, returns:

$sourceSeq[fn:round($startingLoc) le position() and position() lt fn:round($startingLoc) + fn:round($length)]

For detailed type semantics, see [Formal Semantics].

The first item of a sequence is located at position 1, not position 0.

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.

As an exception to the previous two notes, if $startingLoc is -INF and $length is +INF, then fn:round($startingLoc) + fn:round($length) is NaN; since position() lt NaN is always false, the result is an empty sequence.

The reason the function accepts arguments of type xs:double is that many computations on untyped data return an xs:double result; and the reason for the rounding rules is to compensate for any imprecision in these floating-point computations.

Parameters

sourceSeq as item()
startingLoc as xs:double
length as xs:double

Returns

item()*

substring-after#2

declare  function fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?) as xs:string external

Returns the part of $arg1 that follows the first occurrence of $arg2, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Minimal match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string

Returns

xs:string

substring-after#3

declare  function fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string external

Returns the part of $arg1 that follows the first occurrence of $arg2, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Minimal match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string
collation as xs:string

Returns

xs:string

substring-before#2

declare  function fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?) as xs:string external

Returns the part of $arg1 that precedes the first occurrence of $arg2, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Minimal match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string

Returns

xs:string

substring-before#3

declare  function fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string external

Returns the part of $arg1 that precedes the first occurrence of $arg2, taking collations into account.

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.

The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations, and static base uri.

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 this function is determined according to the rules in .

The function 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.

Minimal match is defined in .

A dynamic error may be raised if the specified collation does not support collation units.

Parameters

arg1 as xs:string
arg2 as xs:string
collation as xs:string

Returns

xs:string

substring#2

declare  function fn:substring($sourceString as xs:string?, $start as xs:double) as xs:string external

Returns the portion of the value of $sourceString beginning at the position indicated by the value of $start and continuing for the number of characters indicated by the value of $length.

This function is deterministic, context-independent, and focus-independent.

If the value of $sourceString is the empty sequence, the function returns the zero-length string.

Otherwise, the function returns a string comprising those characters of $sourceString whose index position (counting from one) is greater than or equal to the value of $start (rounded to an integer), and (if $length is specified) less than the sum of $start and $length (both rounded to integers).

The characters returned do not extend beyond $sourceString. If $start 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 satisfies:

fn:round($start) <= $p < fn:round($start) + fn:round($length)

The two argument version of the function assumes that $length is infinite and thus returns the characters in $sourceString whose position $p satisfies:

fn:round($start) <= $p

In the above computations, the rules for op:numeric-less-than and op:numeric-greater-than apply.

The first character of a string is located at position 1, not position 0.

Parameters

sourceString as xs:string
start as xs:double

Returns

xs:string

substring#3

declare  function fn:substring($sourceString as xs:string?, $start as xs:double, $length as xs:double) as xs:string external

Returns the portion of the value of $sourceString beginning at the position indicated by the value of $start and continuing for the number of characters indicated by the value of $length.

This function is deterministic, context-independent, and focus-independent.

If the value of $sourceString is the empty sequence, the function returns the zero-length string.

Otherwise, the function returns a string comprising those characters of $sourceString whose index position (counting from one) is greater than or equal to the value of $start (rounded to an integer), and (if $length is specified) less than the sum of $start and $length (both rounded to integers).

The characters returned do not extend beyond $sourceString. If $start 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 satisfies:

fn:round($start) <= $p < fn:round($start) + fn:round($length)

The two argument version of the function assumes that $length is infinite and thus returns the characters in $sourceString whose position $p satisfies:

fn:round($start) <= $p

In the above computations, the rules for op:numeric-less-than and op:numeric-greater-than apply.

The first character of a string is located at position 1, not position 0.

Parameters

sourceString as xs:string
start as xs:double
length as xs:double

Returns

xs:string

sum#1

declare  function fn:sum($arg as xs:anyAtomicType*) as xs:anyAtomicType external

Returns a value obtained by adding together the values in $arg.

This function is deterministic, context-independent, and focus-independent.

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.

If the converted sequence is empty, then the single-argument form of the function returns the xs:integer value 0; the two-argument form returns the value of the argument $zero.

If the converted sequence contains the value NaN, NaN is returned.

All items in $arg must be numeric or derived from a single base type. In addition, the type must support addition. Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values. For numeric values, the numeric promotion rules defined in are used to promote all values to a single common type. The sum of a sequence of integers will therefore be an integer, while the sum of a numeric sequence that includes at least one xs:double will be an xs:double.

The result of the function, using the second signature, is the result of the expression:

if (fn:count($c) eq 0) then $zero else if (fn:count($c) eq 1) then $c[1] else $c[1] + fn:sum(subsequence($c, 2))

where $c is the converted sequence.

The result of the function, using the first signature, is the result of the expression: fn:sum($arg, 0).

For detailed type semantics, see [Formal Semantics].

A type error is raised if the input sequence contains items of incompatible types, as described above.

Parameters

arg as xs:anyAtomicType

Returns

xs:anyAtomicType

sum#2

declare  function fn:sum($arg as xs:anyAtomicType*, $zero as xs:anyAtomicType?) as xs:anyAtomicType? external

Returns a value obtained by adding together the values in $arg.

This function is deterministic, context-independent, and focus-independent.

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.

If the converted sequence is empty, then the single-argument form of the function returns the xs:integer value 0; the two-argument form returns the value of the argument $zero.

If the converted sequence contains the value NaN, NaN is returned.

All items in $arg must be numeric or derived from a single base type. In addition, the type must support addition. Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values. For numeric values, the numeric promotion rules defined in are used to promote all values to a single common type. The sum of a sequence of integers will therefore be an integer, while the sum of a numeric sequence that includes at least one xs:double will be an xs:double.

The result of the function, using the second signature, is the result of the expression:

if (fn:count($c) eq 0) then $zero else if (fn:count($c) eq 1) then $c[1] else $c[1] + fn:sum(subsequence($c, 2))

where $c is the converted sequence.

The result of the function, using the first signature, is the result of the expression: fn:sum($arg, 0).

For detailed type semantics, see [Formal Semantics].

A type error is raised if the input sequence contains items of incompatible types, as described above.

Parameters

arg as xs:anyAtomicType
zero as xs:anyAtomicType

Returns

xs:anyAtomicType?

tail#1

declare  function fn:tail($arg as item()*) as item()* external

Returns all but the first item in a sequence.

This function is deterministic, context-independent, and focus-independent.

The function returns the value of the expression subsequence($arg, 2)

If $arg is the empty sequence, or a sequence containing a single item, then the empty sequence is returned.

Parameters

arg as item()

Returns

item()*

timezone-from-date#1

declare  function fn:timezone-from-date($arg as xs:date?) as xs:dayTimeDuration? external

Returns the timezone component of an xs:date.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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. If $arg has no timezone component, the result is the empty sequence.

The expression fn:timezone-from-date(xs:date("1999-05-31-05:00")) returns xs:dayTimeDuration("-PT5H").

The expression fn:timezone-from-date(xs:date("2000-06-12Z")) returns xs:dayTimeDuration("PT0S").

Parameters

arg as xs:date

Returns

xs:dayTimeDuration?

timezone-from-dateTime#1

declare  function fn:timezone-from-dateTime($arg as xs:dateTime?) as xs:dayTimeDuration? external

Returns the timezone component of an xs:dateTime.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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. If $arg has no timezone component, the result is the empty sequence.

The expression fn:timezone-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) returns xs:dayTimeDuration("-PT5H").

The expression fn:timezone-from-dateTime(xs:dateTime("2000-06-12T13:20:00Z")) returns xs:dayTimeDuration("PT0S").

The expression fn:timezone-from-dateTime(xs:dateTime("2004-08-27T00:00:00")) returns ().

Parameters

arg as xs:dateTime

Returns

xs:dayTimeDuration?

timezone-from-time#1

declare  function fn:timezone-from-time($arg as xs:time?) as xs:dayTimeDuration? external

Returns the timezone component of an xs:time.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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. If $arg has no timezone component, the result is the empty sequence.

The expression fn:timezone-from-time(xs:time("13:20:00-05:00")) returns xs:dayTimeDuration("-PT5H").

The expression fn:timezone-from-time(xs:time("13:20:00")) returns ().

Parameters

arg as xs:time

Returns

xs:dayTimeDuration?

tokenize#2

declare  function fn:tokenize($input as xs:string?, $pattern as xs:string) as xs:string* external

Returns a sequence of strings constructed by splitting the input wherever a separator is found; the separator is any substring that matches a given regular expression.

This function is deterministic, context-independent, and focus-independent.

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 .

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 function returns the empty sequence.

The function returns a sequence of strings formed by breaking the $input string into a sequence of strings, treating any substring that matches $pattern as a separator. The separators themselves are not returned.

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.

If two alternatives within the supplied $pattern both match at the same position in the $input string, then the match that is chosen is the first. For example:

fn:tokenize("abracadabra", "(ab)|(a)") returns ("", "r", "c", "d", "r", "")

A dynamic error is raised if the value of $pattern is invalid according to the rules described in section .

A dynamic error is raised if the value of $flags is invalid according to the rules described in section .

A dynamic error is raised if the supplied $pattern matches a zero-length string, that is, if fn:matches("", $pattern, $flags) returns true.

Parameters

input as xs:string
pattern as xs:string

Returns

xs:string*

tokenize#3

declare  function fn:tokenize($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:string* external

Returns a sequence of strings constructed by splitting the input wherever a separator is found; the separator is any substring that matches a given regular expression.

This function is deterministic, context-independent, and focus-independent.

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 .

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 function returns the empty sequence.

The function returns a sequence of strings formed by breaking the $input string into a sequence of strings, treating any substring that matches $pattern as a separator. The separators themselves are not returned.

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.

If two alternatives within the supplied $pattern both match at the same position in the $input string, then the match that is chosen is the first. For example:

fn:tokenize("abracadabra", "(ab)|(a)") returns ("", "r", "c", "d", "r", "")

A dynamic error is raised if the value of $pattern is invalid according to the rules described in section .

A dynamic error is raised if the value of $flags is invalid according to the rules described in section .

A dynamic error is raised if the supplied $pattern matches a zero-length string, that is, if fn:matches("", $pattern, $flags) returns true.

Parameters

input as xs:string
pattern as xs:string
flags as xs:string

Returns

xs:string*

trace#2

declare  function fn:trace($value as item()*, $label as xs:string) as item()* external

Provides an execution trace intended to be used in debugging queries.

This function is deterministic, context-independent, and focus-independent.

The function returns the value of $value, unchanged.

In addition, the values of $value, converted to an xs:string, and $label may be directed to a trace data set. The destination of the trace output is . The format of the trace output is . The ordering of output from calls of the fn:trace function is .

Consider a situation in which a user wants to investigate the actual value passed to a function. Assume that in a particular execution, $v is an xs:decimal with value 124.84. Writing fn:trace($v, 'the value of $v is:') will put the strings "124.84" and "the value of $v is:" in the trace data set in implementation dependent order.

Parameters

value as item()
label as xs:string

Returns

item()*

translate#3

declare  function fn:translate($arg as xs:string?, $mapString as xs:string, $transString as xs:string) as xs:string external

Returns the value of $arg modified by replacing or removing individual characters.

This function is deterministic, context-independent, and focus-independent.

If the value of $arg is the empty sequence, the function returns the zero-length string.

Otherwise, the function returns a result string constructed by processing each character in the value of $arg, in order, according to the following rules:

If the character does not appear in the value of $mapString then it is added to the result string unchanged.

If the character first appears in the value of $mapString at some position M, where the value of $transString is M or more characters in length, then the character at position M in $transString is added to the result string.

If the character first appears in the value of $mapString at some position M, where the value of $transString is less than M characters in length, then the character is omitted from the result string.

If $mapString is the zero-length string then the function returns $arg unchanged.

If a character occurs more than once in $mapString, then the first occurrence determines the action taken.

If $transString is longer than $mapString, the excess characters are ignored.

Parameters

arg as xs:string
mapString as xs:string
transString as xs:string

Returns

xs:string

true#0

declare  function fn:true() as xs:boolean external

Returns the xs:boolean value true.

This function is deterministic, context-independent, and focus-independent.

The result is equivalent to xs:boolean("1").

The expression fn:true() returns xs:boolean(1).

Parameters

Returns

xs:boolean

unordered#1

declare  function fn:unordered($sourceSeq as item()*) as item()* external

Returns the items of $sourceSeq in an order.

This function is deterministic, context-independent, and focus-independent.

The function returns the items of $sourceSeq in an order.

Query optimizers may be able to do a better job if the order of the output sequence is not specified. For example, when retrieving prices from a purchase order, if an index exists on prices, it may be more efficient to return the prices in index order rather than in document order.

Parameters

sourceSeq as item()

Returns

item()*

unparsed-text-available#1

declare  function fn:unparsed-text-available($href as xs:string?) as xs:boolean external

Because errors in evaluating the fn:unparsed-text function are non-recoverable, these two functions are provided to allow an application to determine whether a call with particular arguments would succeed.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The fn:unparsed-text-available function determines whether a call on the fn:unparsed-text function with identical arguments would return a string.

If the first argument is an empty sequence, the function returns false. If the second argument is an empty sequence, the function behaves as if the second argument were omitted.

In other cases, the function returns true if a call on fn:unparsed-text with the same arguments would succeed, and false if a call on fn:unparsed-text with the same arguments would fail with a non-recoverable dynamic error.

The functions fn:unparsed-text and fn:unparsed-text-available have the same requirement for determinism as the functions fn:doc and fn:doc-available. This means that unless the user has explicitly stated a requirement for a reduced level of determinism, either of these functions if called twice with the same arguments during the course of a transformation must return the same results each time; moreover, the results of a call on fn:unparsed-text-available must be consistent with the results of a subsequent call on unparsed-text with the same arguments.

This requires that the unparsed-text-available function should actually attempt to read the resource identified by the URI, and check that it is correctly encoded and contains no characters that are invalid in XML. Implementations may avoid the cost of repeating these checks for example by caching the validated contents of the resource, to anticipate a subsequent call on the unparsed-text or unparsed-text-lines function. Alternatively, implementations may be able to rewrite an expression such as if (unparsed-text-available(A)) then unparsed-text(A) else ... to generate a single call internally.

Parameters

href as xs:string

Returns

xs:boolean

unparsed-text-available#1

declare  function fn:unparsed-text-available($href as xs:string?) as xs:boolean external

Because errors in evaluating the fn:unparsed-text function are non-recoverable, these two functions are provided to allow an application to determine whether a call with particular arguments would succeed.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The fn:unparsed-text-available function determines whether a call on the fn:unparsed-text function with identical arguments would return a string.

If the first argument is an empty sequence, the function returns false. If the second argument is an empty sequence, the function behaves as if the second argument were omitted.

In other cases, the function returns true if a call on fn:unparsed-text with the same arguments would succeed, and false if a call on fn:unparsed-text with the same arguments would fail with a non-recoverable dynamic error.

The functions fn:unparsed-text and fn:unparsed-text-available have the same requirement for determinism as the functions fn:doc and fn:doc-available. This means that unless the user has explicitly stated a requirement for a reduced level of determinism, either of these functions if called twice with the same arguments during the course of a transformation must return the same results each time; moreover, the results of a call on fn:unparsed-text-available must be consistent with the results of a subsequent call on unparsed-text with the same arguments.

This requires that the unparsed-text-available function should actually attempt to read the resource identified by the URI, and check that it is correctly encoded and contains no characters that are invalid in XML. Implementations may avoid the cost of repeating these checks for example by caching the validated contents of the resource, to anticipate a subsequent call on the unparsed-text or unparsed-text-lines function. Alternatively, implementations may be able to rewrite an expression such as if (unparsed-text-available(A)) then unparsed-text(A) else ... to generate a single call internally.

Parameters

href as xs:string

Returns

xs:boolean

unparsed-text-available#2

declare  function fn:unparsed-text-available($href as xs:string?, $encoding as xs:string) as xs:boolean external

Because errors in evaluating the fn:unparsed-text function are non-recoverable, these two functions are provided to allow an application to determine whether a call with particular arguments would succeed.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The fn:unparsed-text-available function determines whether a call on the fn:unparsed-text function with identical arguments would return a string.

If the first argument is an empty sequence, the function returns false. If the second argument is an empty sequence, the function behaves as if the second argument were omitted.

In other cases, the function returns true if a call on fn:unparsed-text with the same arguments would succeed, and false if a call on fn:unparsed-text with the same arguments would fail with a non-recoverable dynamic error.

The functions fn:unparsed-text and fn:unparsed-text-available have the same requirement for determinism as the functions fn:doc and fn:doc-available. This means that unless the user has explicitly stated a requirement for a reduced level of determinism, either of these functions if called twice with the same arguments during the course of a transformation must return the same results each time; moreover, the results of a call on fn:unparsed-text-available must be consistent with the results of a subsequent call on unparsed-text with the same arguments.

This requires that the unparsed-text-available function should actually attempt to read the resource identified by the URI, and check that it is correctly encoded and contains no characters that are invalid in XML. Implementations may avoid the cost of repeating these checks for example by caching the validated contents of the resource, to anticipate a subsequent call on the unparsed-text or unparsed-text-lines function. Alternatively, implementations may be able to rewrite an expression such as if (unparsed-text-available(A)) then unparsed-text(A) else ... to generate a single call internally.

Parameters

href as xs:string
encoding as xs:string

Returns

xs:boolean

unparsed-text-available#2

declare  function fn:unparsed-text-available($href as xs:string?, $encoding as xs:string) as xs:boolean external

Because errors in evaluating the fn:unparsed-text function are non-recoverable, these two functions are provided to allow an application to determine whether a call with particular arguments would succeed.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The fn:unparsed-text-available function determines whether a call on the fn:unparsed-text function with identical arguments would return a string.

If the first argument is an empty sequence, the function returns false. If the second argument is an empty sequence, the function behaves as if the second argument were omitted.

In other cases, the function returns true if a call on fn:unparsed-text with the same arguments would succeed, and false if a call on fn:unparsed-text with the same arguments would fail with a non-recoverable dynamic error.

The functions fn:unparsed-text and fn:unparsed-text-available have the same requirement for determinism as the functions fn:doc and fn:doc-available. This means that unless the user has explicitly stated a requirement for a reduced level of determinism, either of these functions if called twice with the same arguments during the course of a transformation must return the same results each time; moreover, the results of a call on fn:unparsed-text-available must be consistent with the results of a subsequent call on unparsed-text with the same arguments.

This requires that the unparsed-text-available function should actually attempt to read the resource identified by the URI, and check that it is correctly encoded and contains no characters that are invalid in XML. Implementations may avoid the cost of repeating these checks for example by caching the validated contents of the resource, to anticipate a subsequent call on the unparsed-text or unparsed-text-lines function. Alternatively, implementations may be able to rewrite an expression such as if (unparsed-text-available(A)) then unparsed-text(A) else ... to generate a single call internally.

Parameters

href as xs:string
encoding as xs:string

Returns

xs:boolean

unparsed-text-lines#1

declare  function fn:unparsed-text-lines($href as xs:string?) as xs:string* external

The fn:unparsed-text-lines function reads an external resource (for example, a file) and returns its contents as a sequence of strings, one for each line of text in the string representation of the resource.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The unparsed-text-lines function reads an external resource (for example, a file) and returns its string representation as a sequence of strings, separated at newline boundaries.

The result of the single-argument function is the same as the result of the expression fn:tokenize(fn:unparsed-text($href), '\r\n|\r|\n')[not(position()=last() and .='')]. The result of the two-argument function is the same as the result of the expression fn:tokenize(fn:unparsed-text($href, $encoding), '\r\n|\r|\n'))[not(position()=last() and .='')].

The result is a thus a sequence of strings containing the text of the resource retrieved using the URI, each string representing one line of text. Lines are separated by one of the sequences x0A, x0D, or x0Dx0A. The characters representing the newline are not included in the returned strings. If there are two adjacent newline sequences, a zero-length string will be returned to represent the empty line; but if the external resource ends with a newline sequence, no zero-length string will be returned as the last item in the result.

Error conditions are the same as for the fn:unparsed-text function.

Parameters

href as xs:string

Returns

xs:string*

unparsed-text-lines#2

declare  function fn:unparsed-text-lines($href as xs:string?, $encoding as xs:string) as xs:string* external

The fn:unparsed-text-lines function reads an external resource (for example, a file) and returns its contents as a sequence of strings, one for each line of text in the string representation of the resource.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The unparsed-text-lines function reads an external resource (for example, a file) and returns its string representation as a sequence of strings, separated at newline boundaries.

The result of the single-argument function is the same as the result of the expression fn:tokenize(fn:unparsed-text($href), '\r\n|\r|\n')[not(position()=last() and .='')]. The result of the two-argument function is the same as the result of the expression fn:tokenize(fn:unparsed-text($href, $encoding), '\r\n|\r|\n'))[not(position()=last() and .='')].

The result is a thus a sequence of strings containing the text of the resource retrieved using the URI, each string representing one line of text. Lines are separated by one of the sequences x0A, x0D, or x0Dx0A. The characters representing the newline are not included in the returned strings. If there are two adjacent newline sequences, a zero-length string will be returned to represent the empty line; but if the external resource ends with a newline sequence, no zero-length string will be returned as the last item in the result.

Error conditions are the same as for the fn:unparsed-text function.

Parameters

href as xs:string
encoding as xs:string

Returns

xs:string*

unparsed-text-lines#2

declare  function fn:unparsed-text-lines($href as xs:string?, $encoding as xs:string) as xs:string* external

The fn:unparsed-text-lines function reads an external resource (for example, a file) and returns its contents as a sequence of strings, one for each line of text in the string representation of the resource.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The unparsed-text-lines function reads an external resource (for example, a file) and returns its string representation as a sequence of strings, separated at newline boundaries.

The result of the single-argument function is the same as the result of the expression fn:tokenize(fn:unparsed-text($href), '\r\n|\r|\n')[not(position()=last() and .='')]. The result of the two-argument function is the same as the result of the expression fn:tokenize(fn:unparsed-text($href, $encoding), '\r\n|\r|\n'))[not(position()=last() and .='')].

The result is a thus a sequence of strings containing the text of the resource retrieved using the URI, each string representing one line of text. Lines are separated by one of the sequences x0A, x0D, or x0Dx0A. The characters representing the newline are not included in the returned strings. If there are two adjacent newline sequences, a zero-length string will be returned to represent the empty line; but if the external resource ends with a newline sequence, no zero-length string will be returned as the last item in the result.

Error conditions are the same as for the fn:unparsed-text function.

Parameters

href as xs:string
encoding as xs:string

Returns

xs:string*

unparsed-text#1

declare  function fn:unparsed-text($href as xs:string?) as xs:string? external

The fn:unparsed-text function reads an external resource (for example, a file) and returns a string representation of the resource.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The $href argument must be a string in the form of a URI reference, which must contain no fragment identifier, and must identify a resource for which a string representation is available. If the URI is a relative URI reference, then it is resolved relative to the Static Base URI property from the static context.

The mapping of URIs to the string representation of a resource is the mapping defined in the available text resources component of the dynamic context.

If the value of the $href argument is an empty sequence, the function returns an empty sequence.

The $encoding argument, if present, is the name of an encoding. The values for this attribute follow the same rules as for the encoding attribute in an XML declaration. The only values which every implementation is required to recognize are utf-8 and utf-16.

The encoding of the external resource is determined as follows:

external encoding information is used if available, otherwise

if the media type of the resource is text/xml or application/xml (see ), or if it matches the conventions text/*+xml or application/*+xml (see and/or its successors), then the encoding is recognized as specified in , otherwise

the value of the $encoding argument is used if present, otherwise

the processor may use implementation-defined heuristics to determine the likely encoding, otherwise

UTF-8 is assumed.

The result of the function is a string containing the string representation of the resource retrieved using the URI.

A dynamic error is raised if $href contains a fragment identifier, or if it cannot be used to retrieve the string representation of a resource.

A dynamic error is raised if the value of the $encoding argument is not a valid encoding name, if the processor does not support the specified encoding, if the string representation of the retrieved resource contains octets that cannot be decoded into Unicode characters using the specified encoding, or if the resulting characters are not permitted XML characters.

A dynamic error is raised if $encoding is absent and the processor cannot infer the encoding using external information and the encoding is not UTF-8.

Parameters

href as xs:string

Returns

xs:string?

unparsed-text#1

declare  function fn:unparsed-text($href as xs:string?) as xs:string? external

The fn:unparsed-text function reads an external resource (for example, a file) and returns a string representation of the resource.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The $href argument must be a string in the form of a URI reference, which must contain no fragment identifier, and must identify a resource for which a string representation is available. If the URI is a relative URI reference, then it is resolved relative to the Static Base URI property from the static context.

The mapping of URIs to the string representation of a resource is the mapping defined in the available text resources component of the dynamic context.

If the value of the $href argument is an empty sequence, the function returns an empty sequence.

The $encoding argument, if present, is the name of an encoding. The values for this attribute follow the same rules as for the encoding attribute in an XML declaration. The only values which every implementation is required to recognize are utf-8 and utf-16.

The encoding of the external resource is determined as follows:

external encoding information is used if available, otherwise

if the media type of the resource is text/xml or application/xml (see ), or if it matches the conventions text/*+xml or application/*+xml (see and/or its successors), then the encoding is recognized as specified in , otherwise

the value of the $encoding argument is used if present, otherwise

the processor may use implementation-defined heuristics to determine the likely encoding, otherwise

UTF-8 is assumed.

The result of the function is a string containing the string representation of the resource retrieved using the URI.

A dynamic error is raised if $href contains a fragment identifier, or if it cannot be used to retrieve the string representation of a resource.

A dynamic error is raised if the value of the $encoding argument is not a valid encoding name, if the processor does not support the specified encoding, if the string representation of the retrieved resource contains octets that cannot be decoded into Unicode characters using the specified encoding, or if the resulting characters are not permitted XML characters.

A dynamic error is raised if $encoding is absent and the processor cannot infer the encoding using external information and the encoding is not UTF-8.

Parameters

href as xs:string

Returns

xs:string?

unparsed-text#2

declare  function fn:unparsed-text($href as xs:string?, $encoding as xs:string) as xs:string? external

The fn:unparsed-text function reads an external resource (for example, a file) and returns a string representation of the resource.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The $href argument must be a string in the form of a URI reference, which must contain no fragment identifier, and must identify a resource for which a string representation is available. If the URI is a relative URI reference, then it is resolved relative to the Static Base URI property from the static context.

The mapping of URIs to the string representation of a resource is the mapping defined in the available text resources component of the dynamic context.

If the value of the $href argument is an empty sequence, the function returns an empty sequence.

The $encoding argument, if present, is the name of an encoding. The values for this attribute follow the same rules as for the encoding attribute in an XML declaration. The only values which every implementation is required to recognize are utf-8 and utf-16.

The encoding of the external resource is determined as follows:

external encoding information is used if available, otherwise

if the media type of the resource is text/xml or application/xml (see ), or if it matches the conventions text/*+xml or application/*+xml (see and/or its successors), then the encoding is recognized as specified in , otherwise

the value of the $encoding argument is used if present, otherwise

the processor may use implementation-defined heuristics to determine the likely encoding, otherwise

UTF-8 is assumed.

The result of the function is a string containing the string representation of the resource retrieved using the URI.

A dynamic error is raised if $href contains a fragment identifier, or if it cannot be used to retrieve the string representation of a resource.

A dynamic error is raised if the value of the $encoding argument is not a valid encoding name, if the processor does not support the specified encoding, if the string representation of the retrieved resource contains octets that cannot be decoded into Unicode characters using the specified encoding, or if the resulting characters are not permitted XML characters.

A dynamic error is raised if $encoding is absent and the processor cannot infer the encoding using external information and the encoding is not UTF-8.

Parameters

href as xs:string
encoding as xs:string

Returns

xs:string?

unparsed-text#2

declare  function fn:unparsed-text($href as xs:string?, $encoding as xs:string) as xs:string? external

The fn:unparsed-text function reads an external resource (for example, a file) and returns a string representation of the resource.

This function is deterministic, context-dependent, and focus-independent. It depends on static base uri.

The $href argument must be a string in the form of a URI reference, which must contain no fragment identifier, and must identify a resource for which a string representation is available. If the URI is a relative URI reference, then it is resolved relative to the Static Base URI property from the static context.

The mapping of URIs to the string representation of a resource is the mapping defined in the available text resources component of the dynamic context.

If the value of the $href argument is an empty sequence, the function returns an empty sequence.

The $encoding argument, if present, is the name of an encoding. The values for this attribute follow the same rules as for the encoding attribute in an XML declaration. The only values which every implementation is required to recognize are utf-8 and utf-16.

The encoding of the external resource is determined as follows:

external encoding information is used if available, otherwise

if the media type of the resource is text/xml or application/xml (see ), or if it matches the conventions text/*+xml or application/*+xml (see and/or its successors), then the encoding is recognized as specified in , otherwise

the value of the $encoding argument is used if present, otherwise

the processor may use implementation-defined heuristics to determine the likely encoding, otherwise

UTF-8 is assumed.

The result of the function is a string containing the string representation of the resource retrieved using the URI.

A dynamic error is raised if $href contains a fragment identifier, or if it cannot be used to retrieve the string representation of a resource.

A dynamic error is raised if the value of the $encoding argument is not a valid encoding name, if the processor does not support the specified encoding, if the string representation of the retrieved resource contains octets that cannot be decoded into Unicode characters using the specified encoding, or if the resulting characters are not permitted XML characters.

A dynamic error is raised if $encoding is absent and the processor cannot infer the encoding using external information and the encoding is not UTF-8.

Parameters

href as xs:string
encoding as xs:string

Returns

xs:string?

upper-case#1

declare  function fn:upper-case($arg as xs:string?) as xs:string external

Converts a string to upper case.

This function is deterministic, context-independent, and focus-independent.

If the value of $arg is the empty sequence, the zero-length string is returned.

Otherwise, the function 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 . 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.

Case mappings may change the length of a string. In general, the fn:upper-case and fn:lower-case functions are not inverses of each other: fn:lower-case(fn:upper-case($arg)) is not guaranteed to return $arg, nor is fn:upper-case(fn:lower-case($arg)). The Latin small letter dotless i (as used in Turkish) is perhaps the most prominent lower-case letter which will not round-trip. The Latin capital letter i with dot above is the most prominent upper-case letter which will not round trip; there are others, such as Latin capital letter Sharp S (#1E9E) which is introduced in Unicode 5.1.

These functions may not always be linguistically appropriate (e.g. Turkish i without dot) or appropriate for the application (e.g. titlecase). In cases such as Turkish, a simple translation should be used first.

Because the function is not sensitive to locale, results will not always match user expectations. In Quebec, for example, the standard uppercase equivalent of "è" is "È", while in metropolitan France it is more commonly "E"; only one of these is supported by the functions as defined.

Many characters of class Ll lack uppercase equivalents in the Unicode case mapping tables; many characters of class Lu lack lowercase equivalents.

Parameters

arg as xs:string

Returns

xs:string

uri-collection#0

declare  function fn:uri-collection() as xs:anyURI* external

Returns a sequence of xs:anyURI values representing the URIs in a resource collection.

This function is deterministic, context-dependent, and focus-independent. It depends on available resource collections, and static base uri.

The zero-argument form of the function returns the URIs in the Default resource collection described in .

If the value of $arg is a relative xs:anyURI, it is resolved against the value of the base-URI property from the static context.

If $arg is the empty sequence, the function behaves as if it had been called without an argument. See above.

The single-argument form of the function returns the sequence of URIs corresponding to the supplied URI in the Available resource collections described in .

A dynamic error is raised if no URI is supplied (that is, if the the function is called with no arguments, or with a single argument that evaluates to an empty sequence), and the value of the default resource collection is absent.

A dynamic error is raised if available resource collections provides no mapping for the absolutized URI.

A dynamic error is raised if $arg is not a valid xs:anyURI.

Parameters

Returns

xs:anyURI*

uri-collection#0

declare  function fn:uri-collection() as xs:anyURI* external

Returns a sequence of xs:anyURI values representing the URIs in a resource collection.

This function is deterministic, context-dependent, and focus-independent. It depends on available resource collections, and static base uri.

The zero-argument form of the function returns the URIs in the Default resource collection described in .

If the value of $arg is a relative xs:anyURI, it is resolved against the value of the base-URI property from the static context.

If $arg is the empty sequence, the function behaves as if it had been called without an argument. See above.

The single-argument form of the function returns the sequence of URIs corresponding to the supplied URI in the Available resource collections described in .

A dynamic error is raised if no URI is supplied (that is, if the the function is called with no arguments, or with a single argument that evaluates to an empty sequence), and the value of the default resource collection is absent.

A dynamic error is raised if available resource collections provides no mapping for the absolutized URI.

A dynamic error is raised if $arg is not a valid xs:anyURI.

Parameters

Returns

xs:anyURI*

uri-collection#1

declare  function fn:uri-collection($arg as xs:string?) as xs:anyURI* external

Returns a sequence of xs:anyURI values representing the URIs in a resource collection.

This function is deterministic, context-dependent, and focus-independent. It depends on available resource collections, and static base uri.

The zero-argument form of the function returns the URIs in the Default resource collection described in .

If the value of $arg is a relative xs:anyURI, it is resolved against the value of the base-URI property from the static context.

If $arg is the empty sequence, the function behaves as if it had been called without an argument. See above.

The single-argument form of the function returns the sequence of URIs corresponding to the supplied URI in the Available resource collections described in .

A dynamic error is raised if no URI is supplied (that is, if the the function is called with no arguments, or with a single argument that evaluates to an empty sequence), and the value of the default resource collection is absent.

A dynamic error is raised if available resource collections provides no mapping for the absolutized URI.

A dynamic error is raised if $arg is not a valid xs:anyURI.

Parameters

arg as xs:string

Returns

xs:anyURI*

uri-collection#1

declare  function fn:uri-collection($arg as xs:string?) as xs:anyURI* external

Returns a sequence of xs:anyURI values representing the URIs in a resource collection.

This function is deterministic, context-dependent, and focus-independent. It depends on available resource collections, and static base uri.

The zero-argument form of the function returns the URIs in the Default resource collection described in .

If the value of $arg is a relative xs:anyURI, it is resolved against the value of the base-URI property from the static context.

If $arg is the empty sequence, the function behaves as if it had been called without an argument. See above.

The single-argument form of the function returns the sequence of URIs corresponding to the supplied URI in the Available resource collections described in .

A dynamic error is raised if no URI is supplied (that is, if the the function is called with no arguments, or with a single argument that evaluates to an empty sequence), and the value of the default resource collection is absent.

A dynamic error is raised if available resource collections provides no mapping for the absolutized URI.

A dynamic error is raised if $arg is not a valid xs:anyURI.

Parameters

arg as xs:string

Returns

xs:anyURI*

year-from-date#1

declare  function fn:year-from-date($arg as xs:date?) as xs:integer? external

Returns the year component of an xs:date.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:integer representing the year in the local value of $arg. The value may be negative.

The expression fn:year-from-date(xs:date("1999-05-31")) returns 1999.

The expression fn:year-from-date(xs:date("2000-01-01+05:00")) returns 2000.

Parameters

arg as xs:date

Returns

xs:integer?

years-from-duration#1

declare  function fn:years-from-duration($arg as xs:duration?) as xs:integer? external

Returns the number of years in a duration.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function 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 ) and then computing the years component as described in .

If $arg is a negative duration then the result will be negative..

If $arg is an xs:dayTimeDuration the function returns 0.

The expression fn:years-from-duration(xs:yearMonthDuration("P20Y15M")) returns 21.

The expression fn:years-from-duration(xs:yearMonthDuration("-P15M")) returns -1.

The expression fn:years-from-duration(xs:dayTimeDuration("-P2DT15H")) returns 0.

Parameters

arg as xs:duration

Returns

xs:integer?

zero-or-one#1

declare  function fn:zero-or-one($arg as item()*) as item()? external

Returns $arg if it contains zero or one items. Otherwise, raises an error.

This function is deterministic, context-independent, and focus-independent.

Except in error cases, the function returns $arg unchanged.

For detailed type semantics, see [Formal Semantics].

A dynamic error is raised if $arg contains more than one item.

Parameters

arg as item()

Returns

item()?