1 Introduction
2 XQuery and XPath Functions
3 XSL Transformations (XSLT) Functions
4 XML Schema
5 Normative References
6 Non-Normative References
This document describes the namespace
http://www.w3.org/2005/xpath-functions
defined by the
[XPath and XQuery Functions and Operators 3.0] and [XSLT 3.0]
specifications (October 2013 and
July 2012 versions, respectively).
This namespace is identified by the namespace prefix fn:
,
which is a predefined prefix.
For updated information, please refer to the latest version of the
[XPath and XQuery Functions and Operators 3.0] and [XSLT 3.0]
specifications.
This document describes the names that are defined in this namespace at the time of publication. The W3C reserves the right to define additional names in this namespace in the future. [XPath and XQuery Functions and Operators 3.0] and [XSLT 3.0] are the only specifications that may amend this namespace.
This document contains a directory of links to related resources, using RDDL (as defined in [Resource Directory Description Language (RDDL)]).
It is GRDDL-enabled (as defined in [Gleaning Resource Descriptions from Dialects of Languages (GRDDL)]); that is to say that a GRDDL-compliant processor can extract useful RDF (as defined in [Resource Description Framework (RDF): Concepts and Abstract Syntax]) representations of the information contained herein.
This section lists all of the functions defined in the
[XPath and XQuery Functions and Operators 3.0] specification. Each
function and operator is uniquely identified with a URI of the form:
“http://www.w3.org/2005/xpath-functions#
name”
where name is the name of a function or operator, such as
“max”: http://www.w3.org/2005/xpath-functions#max
.
The normative definitions of these functions are in the [XPath and XQuery Functions and Operators 3.0] specification. For convenience, a very brief, non-normative summary of each function is provided. For details, follow the link on the “Summary:” introductory text below each function.
numeric? abs(numeric?)
Returns the absolute value of $arg
.
xs:dateTime? adjust-dateTime-to-timezone(xs:dateTime?)
xs:dateTime? adjust-dateTime-to-timezone(xs:dateTime?, xs:dayTimeDuration?)
Adjusts an xs:dateTime
value to a specific timezone, or to no
timezone at all.
xs:date? adjust-date-to-timezone(xs:date?)
xs:date? adjust-date-to-timezone(xs:date?, xs:dayTimeDuration?)
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.
xs:time? adjust-time-to-timezone(xs:time?)
xs:time? adjust-time-to-timezone(xs:time?, xs:dayTimeDuration?)
Adjusts an xs:time
value to a specific timezone, or to no timezone
at all.
element(fn:analyze-string-result) analyze-string(xs:string?, xs:string)
element(fn:analyze-string-result) analyze-string(xs:string?, xs:string, xs:string)
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.
xs:string* available-environment-variables()
Returns a list of environment variable names that are suitable for passing to
fn:environment-variable
, as a (possibly empty) sequence of strings.
xs:anyAtomicType? avg(xs:anyAtomicType*)
Returns the average of the values in the input sequence $arg
, that
is, the sum of the values divided by the number of values.
xs:anyURI? base-uri()
xs:anyURI? base-uri(node()?)
Returns the base URI of a node.
xs:boolean boolean(item()*)
Computes the effective boolean value of the sequence $arg
.
numeric? ceiling(numeric?)
Rounds $arg
upwards to a whole number.
xs:boolean? codepoint-equal(xs:string?, xs:string?)
Returns true if two strings are equal, considered codepoint-by-codepoint.
xs:string codepoints-to-string(xs:integer*)
Creates an xs:string
from a sequence of codepoints.
node()* collection()
node()* collection(xs:string?)
Returns a sequence of nodes representing a collection of documents indentified by a collection URI; or a default collection if no URI is supplied.
xs:integer? compare(xs:string?, xs:string?)
xs:integer? compare(xs:string?, xs:string?, xs:string)
Returns -1, 0, or 1, depending on whether $comparand1
collates
before, equal to, or after $comparand2
according to the rules of a selected
collation.
xs:boolean contains(xs:string?, xs:string?)
xs:boolean contains(xs:string?, xs:string?, xs:string)
Returns true if the string $arg1
contains $arg2
as a
substring, taking collations into account.
xs:integer count(item()*)
Returns the number of items in a sequence.
xs:date current-date()
Returns the current date.
xs:dateTimeStamp current-dateTime()
Returns the current date and time (with timezone).
xs:time current-time()
Returns the current time.
xs:anyAtomicType* data()
xs:anyAtomicType* data(item()*)
Returns the result of atomizing a sequence, that is, replacing all nodes in the sequence by their typed values.
xs:dateTime? dateTime(xs:date?, xs:time?)
Returns an xs:dateTime
value created by combining an
xs:date
and an xs:time
.
xs:integer? day-from-date(xs:date?)
Returns the day component of an xs:date
.
xs:integer? day-from-dateTime(xs:dateTime?)
Returns the day component of an xs:dateTime
.
xs:integer? days-from-duration(xs:duration?)
Returns the number of days in a duration.
xs:boolean deep-equal(item()*, item()*)
xs:boolean deep-equal(item()*, item()*, xs:string)
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.
xs:string default-collation()
Returns the value of the default collation property from the static context.
xs:anyAtomicType* distinct-values(xs:anyAtomicType*)
xs:anyAtomicType* distinct-values(xs:anyAtomicType*, xs:string)
Returns the values that appear in a sequence, with duplicates eliminated.
document-node()? doc(xs:string?)
Retrieves a document using a URI supplied as an
xs:string
, and returns the corresponding document node.
xs:boolean doc-available(xs:string?)
The function returns true if and only if the function
call fn:doc($uri)
would return a document node.
xs:anyURI? document-uri()
xs:anyURI? document-uri(node()?)
Returns the URI of a resource where a document can be found, if available.
element()* element-with-id(xs:string*)
element()* element-with-id(xs:string*, node())
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
.
xs:boolean empty(item()*)
Returns true if the argument is the empty sequence.
xs:string encode-for-uri(xs:string?)
Encodes reserved characters in a string that is intended to be used in the path segment of a URI.
xs:boolean ends-with(xs:string?, xs:string?)
xs:boolean ends-with(xs:string?, xs:string?, xs:string)
Returns true if the string $arg1
contains $arg2
as a
trailing substring, taking collations into account.
xs:string? environment-variable(xs:string)
Returns the value of a system environment variable, if it exists.
none error()
none error(xs:QName)
none error(xs:QName?, xs:string)
none error(xs:QName?, xs:string, item()*)
Calling the fn:error
function raises an application-defined
error.
xs:string escape-html-uri(xs:string?)
Escapes a URI in the same way that HTML user agents handle attribute values expected to contain URIs.
item() exactly-one(item()*)
Returns $arg
if it contains exactly one item. Otherwise, raises an
error.
xs:boolean exists(item()*)
Returns true if the argument is a non-empty sequence.
xs:boolean false()
Returns the xs:boolean
value false
.
item()* filter(item()*, function(item()) as xs:boolean)
Returns those items from the sequence $seq for which the supplied function $f returns true.
numeric? floor(numeric?)
Rounds $arg
downwards to a whole number.
item()* fold-left(item()*, item()*, function(item()*, item()) as item()*)
Processes the supplied sequence from left to right, applying the supplied function repeatedly to each item in turn, together with an accumulated result value.
item()* fold-right(item()*, item()*, function(item()*, item()) as item()*)
Processes the supplied sequence from right to left, applying the supplied function repeatedly to each item in turn, together with an accumulated result value.
item()* for-each(item()*, function(item()) as item()*)
Applies the function item $f to every item from the sequence $seq in turn, returning the concatenation of the resulting sequences in order.
item()* for-each-pair(item()*, item()*, function(item(), item()) as item()*)
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.
xs:string? format-date(xs:date?, xs:string)
xs:string? format-date(xs:date?, xs:string, xs:string?, xs:string?, xs:string?)
Returns a string containing an xs:date
value formatted for display.
xs:string? format-dateTime(xs:dateTime?, xs:string)
xs:string? format-dateTime(xs:dateTime?, xs:string, xs:string?, xs:string?, xs:string?)
Returns a string containing an xs:dateTime
value formatted for display.
xs:string format-integer(xs:integer?, xs:string)
xs:string format-integer(xs:integer?, xs:string, xs:string?)
Formats an integer according to a given picture string, using the conventions of a given natural language if specified.
xs:string format-number(numeric?, xs:string)
xs:string format-number(numeric?, xs:string, xs:string?)
Returns a string containing a number formatted according to a given picture string, taking account of decimal formats specified in the static context.
xs:string? format-time(xs:time?, xs:string)
xs:string? format-time(xs:time?, xs:string, xs:string?, xs:string?, xs:string?)
Returns a string containing an xs:time
value formatted for display.
xs:integer function-arity(function(*))
Returns the arity of the function identified by a function item.
function(*)? function-lookup(xs:QName, xs:integer)
Returns the function having a given name and arity, if there is one.
xs:QName? function-name(function(*))
Returns the name of the function identified by a function item.
xs:string generate-id()
xs:string generate-id(node()?)
This function returns a string that uniquely identifies a given node.
xs:boolean has-children()
xs:boolean has-children(node()?)
Returns true if the supplied node has one or more child nodes (of any kind).
item()? head(item()*)
Returns the first item in a sequence.
xs:integer? hours-from-dateTime(xs:dateTime?)
Returns the hours component of an xs:dateTime
.
xs:integer? hours-from-duration(xs:duration?)
Returns the number of hours in a duration.
xs:integer? hours-from-time(xs:time?)
Returns the hours component of an xs:time
.
element()* id(xs:string*)
element()* id(xs:string*, node())
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
.
node()* idref(xs:string*)
node()* idref(xs:string*, node())
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
.
xs:dayTimeDuration implicit-timezone()
Returns the value of the implicit timezone property from the dynamic context.
xs:integer* index-of(xs:anyAtomicType*, xs:anyAtomicType)
xs:integer* index-of(xs:anyAtomicType*, xs:anyAtomicType, xs:string)
Returns a sequence of positive integers giving the positions within the
sequence $seq
of items that are equal to $search
.
node()* innermost(node()*)
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.
xs:string* in-scope-prefixes(element())
Returns the prefixes of the in-scope namespaces for an element node.
item()* insert-before(item()*, xs:integer, item()*)
Returns a sequence constructed by inserting an item or a sequence of items at a given position within an existing sequence.
xs:string iri-to-uri(xs:string?)
Converts a string containing an IRI into a URI according to the rules of [RFC 3987].
xs:boolean lang(xs:string?)
xs:boolean lang(xs:string?, node())
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
.
xs:integer last()
Returns the context size from the dynamic context.
xs:string local-name()
xs:string local-name(node()?)
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
.
xs:NCName? local-name-from-QName(xs:QName?)
Returns the local part of the supplied QName.
xs:string lower-case(xs:string?)
Converts a string to lower case.
xs:boolean matches(xs:string?, xs:string)
xs:boolean matches(xs:string?, xs:string, xs:string)
Returns true if the supplied string matches a given regular expression.
xs:anyAtomicType? max(xs:anyAtomicType*)
xs:anyAtomicType? max(xs:anyAtomicType*, xs:string)
Returns a value that is equal to the highest value appearing in the input sequence.
xs:anyAtomicType? min(xs:anyAtomicType*)
xs:anyAtomicType? min(xs:anyAtomicType*, xs:string)
Returns a value that is equal to the lowest value appearing in the input sequence.
xs:integer? minutes-from-dateTime(xs:dateTime?)
Returns the minute component of an xs:dateTime
.
xs:integer? minutes-from-duration(xs:duration?)
Returns the number of minutes in a duration.
xs:integer? minutes-from-time(xs:time?)
Returns the minutes component of an xs:time
.
xs:integer? month-from-date(xs:date?)
Returns the month component of an xs:date
.
xs:integer? month-from-dateTime(xs:dateTime?)
Returns the month component of an xs:dateTime
.
xs:integer? months-from-duration(xs:duration?)
Returns the number of months in a duration.
xs:string name()
xs:string name(node()?)
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
.
xs:anyURI namespace-uri()
xs:anyURI namespace-uri(node()?)
Returns the namespace URI part of the name of
$arg
, as an xs:anyURI
value.
xs:anyURI? namespace-uri-for-prefix(xs:string?, element())
Returns the namespace URI of one of the in-scope namespaces for
$element
, identified by its namespace prefix.
xs:anyURI? namespace-uri-from-QName(xs:QName?)
Returns the namespace URI part of the supplied QName.
xs:boolean nilled()
xs:boolean? nilled(node()?)
Returns true for an element that is nilled.
xs:QName? node-name()
xs:QName? node-name(node()?)
Returns the name of a node, as an xs:QName
.
xs:string normalize-space()
xs:string normalize-space(xs:string?)
Returns the value of $arg
with leading and trailing whitespace
removed, and sequences of internal whitespace reduced to a single space character.
xs:string normalize-unicode(xs:string?)
xs:string normalize-unicode(xs:string?, xs:string)
Returns the value of $arg
after applying Unicode
normalization.
xs:boolean not(item()*)
Returns true
if the effective boolean value of $arg
is false
, or false
if it is true
.
xs:double number()
xs:double number(xs:anyAtomicType?)
Returns the value indicated by $arg
or, if $arg
is
not specified, the context item after atomization, converted to an
xs:double
.
item()+ one-or-more(item()*)
Returns $arg
if it contains one or more items. Otherwise, raises
an error.
node()* outermost(node()*)
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.
document-node(element(*))? parse-xml(xs:string?)
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.
document-node()? parse-xml-fragment(xs:string?)
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.
xs:string? path()
xs:string? path(node()?)
Returns a path expression that can be used to select the supplied node relative to the root of its containing document.
xs:integer position()
Returns the context position from the dynamic context.
xs:NCName? prefix-from-QName(xs:QName?)
Returns the prefix component of the supplied QName.
xs:QName QName(xs:string?, xs:string)
Constructs an xs:QName
value given a namespace URI and a lexical
QName.
item()* remove(item()*, xs:integer)
Returns a new sequence containing all the items of $target
except
the item at position $position
.
xs:string replace(xs:string?, xs:string, xs:string)
xs:string replace(xs:string?, xs:string, xs:string, xs:string)
Returns a string produced from the input string by replacing any substrings that match a given regular expression with a supplied replacement string.
xs:QName? resolve-QName(xs:string?, element())
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.
xs:anyURI? resolve-uri(xs:string?)
xs:anyURI? resolve-uri(xs:string?, xs:string)
Resolves a relative IRI reference against an absolute IRI.
item()* reverse(item()*)
Reverses the order of items in a sequence.
node() root()
node()? root(node()?)
Returns the root of the tree to which $arg
belongs. This will
usually, but not necessarily, be a document node.
numeric? round(numeric?)
numeric? round(numeric?, xs:integer)
Rounds a value to a specified number of decimal places, rounding upwards if two such values are equally near.
numeric? round-half-to-even(numeric?)
numeric? round-half-to-even(numeric?, xs:integer)
Rounds a value to a specified number of decimal places, rounding to make the last digit even if two such values are equally near.
xs:decimal? seconds-from-dateTime(xs:dateTime?)
Returns the seconds component of an xs:dateTime
.
xs:decimal? seconds-from-duration(xs:duration?)
Returns the number of seconds in a duration.
xs:decimal? seconds-from-time(xs:time?)
Returns the seconds component of an xs:time
.
xs:string serialize(item()*)
xs:string serialize(item()*, element(output:serialization-parameters)?)
This function serializes the supplied input
sequence
$arg
as described in [XSLT and XQuery Serialization 3.0],
returning the serialized representation of the
sequence as a string.
xs:boolean starts-with(xs:string?, xs:string?)
xs:boolean starts-with(xs:string?, xs:string?, xs:string)
Returns true if the string $arg1
contains $arg2
as a
leading substring, taking collations into account.
xs:anyURI? static-base-uri()
This function returns the value of the Static Base URI property from the static context.
xs:string string()
xs:string string(item()?)
Returns the value of $arg
represented as an
xs:string
.
xs:string string-join(xs:string*)
xs:string string-join(xs:string*, xs:string)
Returns a string created by concatenating the items in a sequence, with a defined separator between adjacent items.
xs:integer string-length()
xs:integer string-length(xs:string?)
Returns the number of characters in a string.
xs:integer* string-to-codepoints(xs:string?)
Returns the sequence of codepoints that
constitute an xs:string
value.
item()* subsequence(item()*, xs:double)
item()* subsequence(item()*, xs:double, xs:double)
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
.
xs:string substring(xs:string?, xs:double)
xs:string substring(xs:string?, xs:double, xs:double)
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
.
xs:string substring-after(xs:string?, xs:string?)
xs:string substring-after(xs:string?, xs:string?, xs:string)
Returns the part of $arg1
that follows the first occurrence of
$arg2
, taking collations into account.
xs:string substring-before(xs:string?, xs:string?)
xs:string substring-before(xs:string?, xs:string?, xs:string)
Returns the part of $arg1
that precedes the first occurrence of
$arg2
, taking collations into account.
xs:anyAtomicType sum(xs:anyAtomicType*)
xs:anyAtomicType? sum(xs:anyAtomicType*, xs:anyAtomicType?)
Returns a value obtained by adding together the values in
$arg
.
item()* tail(item()*)
Returns all but the first item in a sequence.
xs:dayTimeDuration? timezone-from-date(xs:date?)
Returns the timezone component of an xs:date
.
xs:dayTimeDuration? timezone-from-dateTime(xs:dateTime?)
Returns the timezone component of an xs:dateTime
.
xs:dayTimeDuration? timezone-from-time(xs:time?)
Returns the timezone component of an xs:time
.
xs:string* tokenize(xs:string?, xs:string)
xs:string* tokenize(xs:string?, xs:string, xs:string)
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.
item()* trace(item()*, xs:string)
Provides an execution trace intended to be used in debugging queries.
xs:string translate(xs:string?, xs:string, xs:string)
Returns the value of $arg
modified by replacing or removing
individual characters.
xs:boolean true()
Returns the xs:boolean
value true
.
item()* unordered(item()*)
Returns the items of $sourceSeq
in an implementation dependent order.
xs:string? unparsed-text(xs:string?)
xs:string? unparsed-text(xs:string?, xs:string)
The fn:unparsed-text
function reads an external resource (for example, a
file) and returns a string representation of the resource.
xs:boolean unparsed-text-available(xs:string?)
xs:boolean unparsed-text-available(xs:string?, xs:string)
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.
xs:string* unparsed-text-lines(xs:string?)
xs:string* unparsed-text-lines(xs:string?, xs:string)
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.
xs:string upper-case(xs:string?)
Converts a string to upper case.
xs:anyURI* uri-collection()
xs:anyURI* uri-collection(xs:string?)
Returns a sequence of xs:anyURI
values representing the URIs in a resource collection.
xs:integer? year-from-date(xs:date?)
Returns the year component of an xs:date
.
xs:integer? year-from-dateTime(xs:dateTime?)
Returns the year component of an xs:dateTime
.
xs:integer? years-from-duration(xs:duration?)
Returns the number of years in a duration.
item()? zero-or-one(item()*)
Returns $arg
if it contains zero or one items. Otherwise, raises
an error.
This section lists all of the functions defined in the
[XSLT 3.0] specification. Each
function and operator is uniquely identified with a URI of the form:
“http://www.w3.org/2005/xpath-functions#
name”
where name is the name of a function or operator, such as
“system-property”: http://www.w3.org/2005/xpath-functions#system-property
.
The normative definitions of these functions are in the [XSLT 3.0] specification. For convenience, a very brief, non-normative summary of each function is provided. For details, follow the link on the “Summary:” introductory text below each function.
The function fn:analyze-string()
, identified in section 3 XSL Transformations (XSLT) Functions above,
returns results that are always valid according to an XML Schema specified in [XPath and XQuery Functions and Operators 3.0].
That XML Schema defined four XML elements and three XML Schema complex types. The XML elements are named:
<analyze-string-result>
<match>
<non-match>
<group>
The XML Schema complex types are named:
analyze-string-result-type
match-type
group-type
The target namespace of this XML Schema is http://www.w3.org/2005/xpath-functions
.
This schema specifies the XML syntax of the result returned by fn:analyze-string
as defined in
[XPath and XQuery Functions and Operators 3.0].
It is located at
http://www.w3.org/2013/10/xpath-functions-30/analyze-string.xsd.
These documents describe the names that are defined in this namespace at the time of publication. The W3C reserves the right to define additional names in this namespace in the future.
XPath and XQuery Functions and Operators 3.0 (22 October 2013 version)
XSL Transformations (XSLT) 3.0 (10 July 2012 version)
Resource Directory Description Language (RDDL) (4 July 2007)
Gleaning Resource Descriptions from Dialects of Languages (GRDDL) (Recommendation of 11 September 2007)
Resource Description Framework (RDF): Concepts and Abstract Syntax (Recommendation of 10 February 2004)