Saxon home page

XPath 2.0 Functions

The list on this page indicates which XPath 2.0 functions are implemented in this Saxon release, and any restrictions in the current implementation.

Functions defined in the XSLT 2.0 specification are not currently listed.

fn:add-timezone-to-date( date $srcval) => date

Sets the timezone information on a date value to the system timezone

XPath 2.0 Specification

** Not yet implemented **


fn:add-timezone-to-date( date $srcval, dayTimeDuration $timezone) => date

Sets the timezone information on a date value to $timezone

XPath 2.0 Specification

Not implemented. Not present in Jan 2003 draft.

fn:add-timezone-to-dateTime( dateTime $srcval) => dateTime

Sets the timezone information on a dateTime value to the system timezone

XPath 2.0 Specification

** Not yet implemented **


fn:add-timezone-to-dateTime( dateTime $srcval, dayTimeDuration $timezone) => dateTime

Sets the timezone information on a dateTime value to $timezone

XPath 2.0 Specification

Not implemented. Not present in Jan 2003 draft.

fn:add-timezone-to-time( time $srcval) => time

Sets the timezone information on a time value to the system timezone

XPath 2.0 Specification

** Not yet implemented **


fn:add-timezone-to-time( time $srcval, dayTimeDuration $timezone) => time

Sets the timezone information on a time value to $timezone

XPath 2.0 Specification

Not implemented. Not present in Jan 2003 draft.

fn:avg(atomicValue* $srcval) => numeric?

Returns the average of a set of numbers

XPath 2.0 Specification

Implemented. Changed in 7.4 to return the same type as the argument, when appropriate. (For a set of integers, the result is a double). Not yet implemented for other addable types, e.g. duration.

fn:base-uri(node $srcval) => anyURI?,returns String

Returns the base URI of a given node

XPath 2.0 Specification


fn:boolean(item* $srcval) => boolean

Obtains the effective boolean value of any expression

XPath 2.0 Specification


fn:ceiling(numeric? $srcval) => numeric?

Rounds a value towards positive infinity

XPath 2.0 Specification

Implemented. Changed in 7.4 to return the same type as the supplied argument.

fn:codepoints-to-string(integer* codes) => string

Converts a sequence of integers representing Unicode characters to the corresponding string

XPath 2.0 Specification


fn:collection(string $srcval) => node*

Loads an external collection of nodes identified by the URI of the collection

XPath 2.0 Specification

** Not yet implemented **


fn:compare(string? $comparand1, string? $comparand2) => integer?

Compares two strings using the default collation

XPath 2.0 Specification


fn:compare(string? $comparand1, string? $comparand2, anyURI $collationLiteral) => integer?

Compares two strings using a specified collation

XPath 2.0 Specification

y (collation is a string)

Note: In Saxon, the collation is represented as a string


fn:concat(string $arg1, ...) => string

Concatenates the string-values of the arguments into a single string

XPath 2.0 Specification


fn:contains(string? $operand1, string? $operand2) => boolean?

Returns true if the second string is a substring of the first

XPath 2.0 Specification


fn:contains(string? $operand1, string? $operand2, anyURI $collationLiteral) => boolean?

XPath 2.0 Specification


fn:context-item() => item?

XPath 2.0 Specification


fn:count(item* $srcval) => unsignedInt

Counts the number of items in a sequence

XPath 2.0 Specification

Note: Currently returns an integer, not an unsignedInt


fn:current-date() => date

Returns the current date

XPath 2.0 Specification


fn:current-dateTime() => dateTime

Returns the current date and time

XPath 2.0 Specification


fn:current-time() => time

Returns the current time

XPath 2.0 Specification


fn:data(node $srcval) => atomic value*

Returns the typed value of a node

XPath 2.0 Specification

Implemented with a single node as the argument. Signature in Jan 2003 draft has item* as the argument.

fn:dayTimeDuration-from-seconds( double seconds) => dayTimeDuration

XPath 2.0 Specification

Implemented, but no longer defined in the spec

fn:deep-equal(node $parameter1, node $parameter2) => boolean

Compares two nodes for deep equality: the names and contents must be identical

XPath 2.0 Specification


fn:deep-equal(node $parameter1, node $parameter2, anyURI $collation) => boolean

Compares two nodes for deep equality; string values are compared using the named collation

XPath 2.0 Specification


fn:default-collation() => anyURI

Returns the name of the default collation

XPath 2.0 Specification

Implemented. In Saxon this always returns a value: if no default collation has been specified explicitly, it returns the URI of the code-point collation.

fn:distinct-nodes( node* $srcval) => node*

Eliminates nodes with duplicate values

XPath 2.0 Specification


fn:distinct-values( item* $srcval) => item*

Returns the set of distinct values present in a given sequence

XPath 2.0 Specification


fn:distinct-values( item* $srcval, anyURI $collationLiteral) => item*

Returns the set of distinct values present in a given sequence, comparing strings using a named collation.

XPath 2.0 Specification


fn:document(item* $srcval1) => node*

Loads one or more documents identified by their URIs

XPath 2.0 Specification


fn:document(item* $srcval1, node* $srcval2) => node*

Loads one or more documents identified by their URIs, using the base URI of the node given in the second argument to resolve any relative URIs

XPath 2.0 Specification


fn:empty(item* $srcval) => boolean

Returns true if the given sequence is empty

XPath 2.0 Specification


fn:ends-with(string? $operand1, string? $operand2) => boolean?

Returns true if the first string ends with the second string

XPath 2.0 Specification


fn:ends-with(string? $operand1, string? $operand2, anyURI $collationLiteral) => boolean?

Returns true if the first string ends with the second string, when compared using the named collation

XPath 2.0 Specification


fn:error()

Raises an error.

XPath 2.0 Specification


fn:error(item $srcval)

Raises an error. The string value of the supplied item is used as the error message.

XPath 2.0 Specification


fn:escape-uri(string $uri-part, boolean $escape-reserved) => string

Applies the %HH escaping convention to a URI

XPath 2.0 Specification


fn:exists(item* $srcval) => boolean

Returns true if the given sequence is not empty

XPath 2.0 Specification


fn:expanded-QName( string $paramURI, string $paramLocal) => QName

Constructs a QName value from a URI and local name

XPath 2.0 Specification


fn:false() => boolean

Returns the boolean value false

XPath 2.0 Specification


fn:floor(numeric? $srcval) => numeric?

Rounds a number towards minus infinity

XPath 2.0 Specification

Implemented. Changed in 7.4 to return the same type as the supplied argument.

fn:get-day-from-date( date? $srcval) => integer?

Extracts the day component of a date value

XPath 2.0 Specification


fn:get-day-from-dateTime( dateTime? $srcval) => integer?

Extracts the day component of a dateTime value

XPath 2.0 Specification


fn:get-days-from-dayTimeDuration( dayTimeDuration? $srcval) => integer?

Extracts the days component of a dayTimeDuration value

XPath 2.0 Specification


fn:get-dayTimeDuration-from-dateTimes( dateTime $srcval1, dateTime $srcval2) => dayTimeDuration

Returns the difference between two dateTimes in the form of a dayTimeDuration

XPath 2.0 Specification


fn:get-hours-from-dateTime( dateTime? $srcval) => integer?

Extracts the hour component of a dateTime value

XPath 2.0 Specification


fn:get-hours-from-dayTimeDuration( dayTimeDuration? $srcval) => integer?

Extracts the hours component of a dayTimeDuration value

XPath 2.0 Specification


fn:get-hours-from-time( time? $srcval) => integer?

Extracts the hours component of a time value

XPath 2.0 Specification


fn:get-in-scope-namespaces( element? $element) => string*

Returns the names of the namespaces that are in scope for an element

XPath 2.0 Specification


fn:get-local-name-from-QName( QName? $srcval) => string?

Extracts the local name component of a QName value

XPath 2.0 Specification


fn:get-minutes-from-dateTime( dateTime? $srcval) => integer?

Extracts the minutes component of a dateTime value

XPath 2.0 Specification


fn:get-minutes-from-dayTimeDuration( dayTimeDuration? $srcval) => integer?

Extracts the minutes component of a dayTimeDuration value

XPath 2.0 Specification


fn:get-minutes-from-time( time? $srcval) => integer?

Extracts the minutes component of a time value

XPath 2.0 Specification


fn:get-month-from-date( date? $srcval) => integer?

Extracts the month component of a date value

XPath 2.0 Specification


fn:get-month-from-dateTime( dateTime? $srcval) => integer?

Extracts the month component of a dateTime value

XPath 2.0 Specification


fn:get-months-from-yearMonthDuration( yearMonthDuration? $srcval) => integer?

Extracts the months component of a yearMonthDuration value

XPath 2.0 Specification


fn:get-namespace-from-QName( QName? $srcval) => anyURI?

Extracts the namespace URI component of a QName value

XPath 2.0 Specification


fn:get-namespace-uri-for-prefix( element $element, string $prefix) => anyURI?

Returns the namespace URI corresponding to a given prefix, using the namespaces that are in scope for a given element

XPath 2.0 Specification

Implemented. Currently returns a string, not an xs:anyURI

fn:get-seconds-from-dateTime( dateTime? $srcval) => decimal?

Extracts the seconds component of a dateTime value

XPath 2.0 Specification


fn:get-seconds-from-dayTimeDuration( dayTimeDuration? $srcval) => integer?

Extracts the seconds component of a dayTime value

XPath 2.0 Specification


fn:get-seconds-from-time( time? $srcval) => decimal?

Extracts the seconds component of a time value

XPath 2.0 Specification


fn:get-timezone-from-date( date? $srcval) => string?

Extracts the timezone component of a date value

XPath 2.0 Specification


fn:get-timezone-from-dateTime( dateTime? $srcval) => string?

Extracts the timezone component of a dateTime value

XPath 2.0 Specification


fn:get-timezone-from-time( time? $srcval) => string?

Extracts the timezone component of a time value

XPath 2.0 Specification


fn:get-year-from-date( date? $srcval) => integer?

Extracts the year component of a date value

XPath 2.0 Specification


fn:get-year-from-dateTime( dateTime? $srcval) => integer?

Extracts the year component of a dateTime value

XPath 2.0 Specification


fn:get-yearMonthDuration-from-dateTimes( dateTime $srcval1, dateTime $srcval2) => yearMonthDuration

Returns the difference between two dateTime values in the form of a yearMonthDuration

XPath 2.0 Specification

** Not yet implemented **


fn:get-years-from-yearMonthDuration( yearMonthDuration? $srcval) => integer?

Extracts the years component of a yearMonthDuration value

XPath 2.0 Specification


fn:id(IDREF* $srcval) => element*

Finds the elements with given ID attribute values

XPath 2.0 Specification

Note: Implemented according to the XPath 1.0 specification


fn:idref(string* $srcval) => element*

Finds the elements that link to the element with a given ID value

XPath 2.0 Specification

** Not yet implemented **


fn:implicit-timezone() => dayTimeDuration

Returns the implicit timezone

XPath 2.0 Specification

** Not yet implemented **


fn:index-of(item* $seqParam, item $srchParam) => unsignedInt*

Finds the positions of items in a sequence that match the second argument

XPath 2.0 Specification


fn:index-of(item* $seqParam, item $srchParam, anyURI $collationLiteral) => unsignedInt*

Finds the positions of items in a sequence that match the second argument, using a named collation for the comparison

XPath 2.0 Specification


fn:input() => node*

Returns the sequence of nodes established by the calling environment as the current input collection

XPath 2.0 Specification

Note: This implementation of the input() function is very simple. If the parameter {http://saxon.sf.net/}input has been supplied to the transformation, the function returns the value of this parameter. This must be a node sequence - which means it cannot be supplied from the command line. If no such parameter has been supplied, it returns the root of the principal source document (the document containing the node that was matched on entry to the transformation).


fn:insert(item* $target, decimal $position, item* $inserts) => item*

Insert an item into a sequence

XPath 2.0 Specification


fn:item-at(item* $seqParam, decimal $posParam) => item?

Return the item at a given position in a sequence

XPath 2.0 Specification

Note: Currently returns an empty sequence rather than raising an error if the index is out of range


fn:lang(string $testlang) => boolean

Returns true if the xml:lang value for the context node matches the given language

XPath 2.0 Specification


fn:last() => unsignedInt?

Returns the context size (the size of the sequence of items currently being processed)

XPath 2.0 Specification


fn:local-name() => string

Returns the local part of the name of the context node

XPath 2.0 Specification


fn:local-name(node? $srcval) => string

Returns the local part of the name of a given node

XPath 2.0 Specification


fn:lower-case(string? $srcval) => string?

Translates characters in a string to lower case

XPath 2.0 Specification


fn:matches(string? $input, string? $pattern) => boolean?

Returns true if the given string matches the given regular expression

XPath 2.0 Specification

Note: The regular expression syntax supported in Saxon is that of JDK 1.4


fn:matches(string? $input, string? $pattern, string? $flags) => boolean?

Returns true if the given string matches the given regular expression, specifying flags to control the way pattern matching is performed

XPath 2.0 Specification

Note: The regular expression syntax supported in Saxon is that of JDK 1.4


fn:max(item* $srcval) => anySimpleType?

Returns the highest value in a sequence of comparable items

XPath 2.0 Specification

Implemented. Changed in 7.4 to support any comparable type

fn:max(item* $srcval, anyURI $collationLiteral) => anySimpleType?

Returns the highest value in a sequence of strings, using a specified collation to perform the comparisons

XPath 2.0 Specification

Implemented in 7.4

fn:min(item* $srcval) => anySimpleType?

Returns the lowest value in a sequence of comparable items

XPath 2.0 Specification

Implemented. Changed in 7.4 to support any comparable type

fn:min(item* $srcval, anyURI $collationLiteral) => anySimpleType?

Returns the lowest value in a sequence of strings, using a specified collation to perform the comparisons

XPath 2.0 Specification

Implemented in 7.4

fn:name() => string

Returns the name of the context node, as a string in the lexical form of a QName

XPath 2.0 Specification


fn:name(node? $srcval) => string

Returns the name of a given node, as a string in the lexical form of a QName

XPath 2.0 Specification


fn:namespace-uri() => string

Returns the namespace URI of the name of the context node

XPath 2.0 Specification


fn:namespace-uri(node? $srcval) => string

Returns the namespace URI of the name of a given node

XPath 2.0 Specification


fn:node-kind(node $srcval) => string

Identifies what kind of node the argument is, as a string, for example "element" or "attribute"

XPath 2.0 Specification


fn:node-name(node $srcval) => QName?

Returns the name of the given node, as a QName value (that is, a namespace URI plus local name)

XPath 2.0 Specification


fn:normalize-space( string? $srcval) => string?

Eliminates redundant spaces from a string

XPath 2.0 Specification


fn:normalize-unicode( string? $srcval) => string?

Converts a string to Unicode normalized form NFC by modifying the way in which combining characters are represented

XPath 2.0 Specification

** Not yet implemented **


fn:normalize-unicode( string? $srcval, string $normalizationForm) => string?

Converts a string to a given Unicode normalized form by modifying the way in which combining characters are represented

XPath 2.0 Specification

** Not yet implemented **


fn:not(item* $srcval) => boolean

Returns true if the effective boolean value of the argument is false, and vice versa

XPath 2.0 Specification


fn:number() => double

Converts the string value of the context node to a number

XPath 2.0 Specification


fn:number(node $srcval) => double

Converts the string value of the given node to a number

XPath 2.0 Specification

Note: Implementation follows the XPath 1.0 specification. Changed in 7.4 so that if the argument is the empty sequence, the result is the empty sequence - this causes some backwards compatibility problems.


fn:position() => unsignedInt?

Returns the context position (that is, the position of the context item in the sequence currenly being processed)

XPath 2.0 Specification


fn:QName-in-context(string $qname, boolean $use-default) => QName

Expands a lexical QName using the in-scope namespaces from the static context

XPath 2.0 Specification

** Not yet implemented **


fn:QName-in-context(string $qname, boolean $use-default, node $node) => QName

Expands a lexical QName using the in-scope namespaces for a given node

XPath 2.0 Specification

** Not yet implemented **


fn:remove(item* $target, decimal $position) => item*

Removes the item at a given position in a sequence

XPath 2.0 Specification


fn:remove-timezone-from-date( date $srcval) => date

Removes the timezone information from a date value

XPath 2.0 Specification

** Not yet implemented **


fn:remove-timezone-from-dateTime( dateTime $srcval) => dateTime

Removes the timezone information from a dateTime value

XPath 2.0 Specification

** Not yet implemented **


fn:remove-timezone-from-dateTime( dateTime $srcval, dayTimeDuration $timezone) => dateTime

Removes the timezone information from a dateTime value, substituting the given timezone

XPath 2.0 Specification

Not implemented, no longer defined in Jan 2003 draft

fn:remove-timezone-from-time( time $srcval) => time

Removes the timezone information from a time value

XPath 2.0 Specification

** Not yet implemented **


fn:remove-timezone-from-time( time $srcval, dayTimeDuration $timezone) => time

Removes the timezone information from a time value, substituting the given timezone

XPath 2.0 Specification

Not implemented, no longer defined in Jan 2003 draft

fn:replace(string? $input, string? $pattern, string? $replacement) => string?

Replaces sequences of characters within a string that match a given regular expression

XPath 2.0 Specification

Note: The regular expression syntax supported in Saxon is that of JDK 1.4


fn:replace(string? $input, string? $pattern, string? $replacement, string? $flags) => string?

Replaces sequences of characters within a string that match a given regular expression, specifying flags to control the way the regular expression is matched

XPath 2.0 Specification

Note: The regular expression syntax supported in Saxon is that of JDK 1.4


fn:resolve-uri(anyURI $relative) => anyURI

Resolves a relative URI against the base URI from the static context

XPath 2.0 Specification

** Not yet implemented **


fn:resolve-uri(anyURI $relative, anyURI $base) => anyURI

Resolves a relative URI against a given base URI

XPath 2.0 Specification

** Not yet implemented **


fn:root(node $srcval) => node

Returns the root node (document node) of the tree containing the given node

XPath 2.0 Specification


fn:round(numeric? $srcval) => numeric?

Rounds a numeric value to the nearest whole number, rounding x.5 towards positive infinity.

XPath 2.0 Specification

Implemented. Changed in 7.4 to return the same type as the supplied argument.

fn:round-half-to-even(numeric? $srcval) => numeric?

Rounds a numeric value to the nearest whole number, rounding x.5 towards the nearest even number.

XPath 2.0 Specification

** Not yet implemented **


fn:round-half-to-even(numeric? $srcval, integer $precision) => numeric?

Rounds a numeric value to the nearest integer multiple of 10 the power of minus precision, rounding x.5 towards the nearest number whose last digit is even.

XPath 2.0 Specification

** Not yet implemented **

Note: Second argument has the wrong type in January draft


fn:sequence-deep-equal( item* $parameter1, item* $parameter2) => boolean?

Tests whether two sequences contain items that are pairwise deep-equal

XPath 2.0 Specification


fn:sequence-deep-equal( item* $parameter1, item* $parameter2, anyURI $collationLiteral) => boolean?

Tests whether two sequences contain items that are pairwise deep-equal, using the given collation to compare string values

XPath 2.0 Specification


fn:sequence-node-equal( node* $parameter1, node* $parameter2) => boolean?

Tests whether two sequences contain identical nodes in identical positions

XPath 2.0 Specification


fn:starts-with(string? $operand1, string? $operand2) => boolean?

Tests whether one string starts with another string

XPath 2.0 Specification


fn:starts-with(string? $operand1, string? $operand2, anyURI $collationLiteral) => boolean?

Tests whether one string starts with another string, using the given collation for comparison

XPath 2.0 Specification


fn:string() => string

Returns the string value of the context node

XPath 2.0 Specification


fn:string(item $srcval) => string

Returns the string value of the argument

XPath 2.0 Specification


fn:string-join(string* $sequence, string $separator) => string

Concatenates all the strings in the given sequence, separated by the given separator

XPath 2.0 Specification


fn:string-length(string? $srcval) => integer?

Returns the number of characters in the given string

XPath 2.0 Specification


fn:string-pad(string? $padString, decimal? $padCount) => string?

Returns a string obtained by concatenating $padCount occurrences of $padString

XPath 2.0 Specification


fn:string-to-codepoints(string $srcval) => integer*

Returns a sequence of integers representing the Unicode codepoints of the characters in the supplied string

XPath 2.0 Specification


fn:subsequence(item* $sourceSeq, decimal $startingLoc) => item*

Returns those items in the given sequence from the given starting position to the end of the sequence

XPath 2.0 Specification


fn:subsequence(item* $sourceSeq, decimal $startingLoc, decimal $length) => item*

Returns those items in the given sequence from the given starting position up to the position implied by the given length

XPath 2.0 Specification


fn:substring(string? $sourceString, decimal? $startingLoc) => string?

Returns a substring of a given string starting at the given starting position and continuing to the end of the string

XPath 2.0 Specification


fn:substring(string? $sourceString, decimal? $startingLoc, decimal? $length) => string?

Returns a subtring of a given string, starting at a given position and continuing up to a given length

XPath 2.0 Specification


fn:substring-after( string? $operand1, string? $operand2) => string?

Returns that part of the given input string that occurs after the first occurrence of the string given in $operand2

XPath 2.0 Specification


fn:substring-after( string? $operand1, string? $operand2, anyURI $collationLiteral) => string?

Returns that part of the given input string that occurs after the first occurrence of the string given in $operand2, using the given collation to compare strings

XPath 2.0 Specification


fn:substring-before( string? $operand1, string? $operand2) => string?

Returns that part of the given input string that occurs before the first occurrence of the string given in $operand2

XPath 2.0 Specification


fn:substring-before( string? $operand1, string? $operand2, anyURI $collationLiteral) => string?

Returns that part of the given input string that occurs before the first occurrence of the string given in $operand2, using the given collation to compare strings

XPath 2.0 Specification


fn:subtract-dateTimes-yielding-dayTimeDuration( dateTime? $operand1, dateTime? $operand2) => dayTimeDuration?

Returns the difference between two dateTimes as a dayTimeDuration

XPath 2.0 Specification

** Not yet implemented **


fn:subtract-dateTimes-yielding-yearMonthDuration( dateTime? $operand1, dateTime? $operand2) => yearMonthDuration?

Returns the difference between two dateTimes as a yearMonthDuration

XPath 2.0 Specification

** Not yet implemented **


fn:sum(atomicValue* $srcval) => numeric

Returns the total of a sequence of numbers

XPath 2.0 Specification

Implemented. In 7.4, works on all numeric types and returns the same type as the arguments. Not implemented for other addable types, e.g. duration.

fn:tokenize(string? $input, string? $pattern) => string*

Returns a sequence of strings formed by breaking the input string at any substring that matches the given regular expression

XPath 2.0 Specification

Note: The regular expression syntax supported in Saxon is that of JDK 1.4


fn:tokenize(string? $input, string? $pattern, string? $flags) => string*

Returns a sequence of strings formed by breaking the input string at any substring that matches the given regular expression, using flags to control the way regular expression matching is performed

XPath 2.0 Specification

Note: The regular expression syntax supported in Saxon is that of JDK 1.4


fn:translate(string? $srcval, string? $mapString, string? $transString) => string?

Returns a string formed by replacing individual characters that appear in the second argument with the characters that appear at the corresponding position in the third argument

XPath 2.0 Specification


fn:true() => boolean

Return the boolean value true

XPath 2.0 Specification


fn:unparsed-entity-uri(string $srcval) => string

Return the system ID of an unparsed entity, given its name

XPath 2.0 Specification


fn:unparsed-entity-public-id(string $srcval) => string

Return the public ID of an unparsed entity, given its name

XPath 2.0 Specification


fn:unparsed-text(string $uri, string $encoding) => string?

Returns the contents of an external text file, given its URI and encoding

XPath 2.0 Specification

Implemented (but needs checking against latest spec)

fn:unordered(item* $sequence) => item*

Returns a random permutation of its argument

XPath 2.0 Specification

Note: In practice the only important case where this function has any effect in the Saxon implementation is where the sequence supplied as argument is a Step using a reverse axis: for example, unordered(ancestor::*) returns the ancestors in reverse document order. But applications should not rely on the actual order; the function is intended to be used by applications that do not care about the order of the results.


fn:upper-case(string? $srcval) => string?

Converts a string to upper case

XPath 2.0 Specification


fn:yearMonthDuration-from-months(int months) => yearMonthDuration

XPath 2.0 Specification

Implemented, but no longer in the spec

Michael H. Kay
14 February 2003