B

XPath Functions

This appendix includes a complete list (as of when this book was written) of functions that can be called by XPath expressions (including those from XQuery and XSLT) to process and manipulate values. The functions are marked as to the XPath version in which they were introduced: XPath 1 in 1999, XPath 2 in 2006, or XPath 3, still a draft for this edition of Beginning XML but considered close to final. The list does not include extensions to XPath by other languages such as Java or PHP or SQL, and does not include the XPath 1.1 draft since that was obsoleted by XPath 2.


image NOTE If you are using an XPath 1 engine, such as those found in web browsers, PHP, Python, Perl, and many other languages, keep to the functions marked for 1.0.


image NOTE See www.expath.org for some extra functions that are fairly widely implemented, and also for some implementations of XSLT 2 and XPath 2 functions that work in XSLT 1.

The tables in this appendix give an alphabetical list of functions roughly sorted into the following categories:

  • Boolean functions
  • Time and Data
  • Files and the Environment
  • Functions that Operate on Functions
  • Functions that Operate on Items
  • Numeric Functions
  • Functions that Operate on Nodes
  • Functions that Operate on QNames
  • Functions that Operate on Sequences
  • Functions that Operate on Strings and URIs
  • Functions to Construct Objects by XSD Type

Each table gives three items for each function:

1. The function name, with its signature
2. The XPath version in which the function first appeared, in a table column headed V to save space
3. A short description

The functions are shown in the Functions and Operators namespace, which in XQuery is bound by default to the prefix fn. Because this is the default namespace, you can actually omit the fn: in most cases. In XSLT the prefix is not bound by default, and you should either bind it yourself or just omit the prefix entirely, because, again, it’s the default. If you need to bind them, use the following URIs:

The information about Schema types makes sense only for XPath 2 and later. XSLT 2 and XQuery 1.0 used XPath 2.0, but in XPath 1 everything was a string or numeric or simply untyped, and there were no XML Schema type names. For example, the first function in the first table, fn:boolean(), is declared as taking a single argument, $arg. The $arg argument must have a type that matches a sequence of zero or more (because of the ) things, each of which match item(). You’d call the function, for example, boolean(/book/@isPaperback) and it would return xs:boolean.

A full explanation of the XPath type notation is beyond the scope of a Beginning book, but if you need it you can refer the References section at the end of the XPath specification (http://www.w3.org/TR/), which is more readable than you might expect!

Some of the functions appear more than once in this appendix, with different numbers of arguments. This is sometimes called function overloading; the XPath engine decides which version of the function to call based on the number of arguments you give it. Often there is a zero-argument version that will default to using the context item, so you can use it in a predicate. For example, the following code finds all chapter titles that are more than 100 characters long.

/book/chapter/title[string-length() > 100]

A few functions were originally defined in XSLT, and were not available for use in XPath or XQuery. Later most of them were moved into the Functions and Operators document so that they could also be part of both XPath and XQuery as well as XSLT. They have been marked as such so you know whether you can use them in specific environments such as XPath 1.

Boolean Functions

Boolean functions operate on the values true and false, represented in XPath as true() and false().

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:boolean($arg as item()∗) as xs:boolean 1.0 Computes the effective boolean value of the sequence $arg.
fn:not($arg as item()∗) as xs:boolean 1.0 Returns true if the effective boolean value of $arg is false, or false if it is true.
fn:true() as xs:boolean 1.0 Returns the xs:boolean value true.

Time and Date Functions

Time and Date functions operate on values defined by XML Schema to represent times, dates, and durations.

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:adjust-dateTime-to-timezone ($arg as xs:dateTime?) as xs:dateTime 2.0 Adjusts an xs:dateTime value to a specific time zone, or to no time zone at all.
fn:adjust-dateTime-to-timezone ($arg as xs:dateTime?, $timezone as xs:dayTimeDuration?) as xs:dateTime 2.0
fn:adjust-date-to-timezone ($arg as xs:date?) as xs:date? 2.0 Adjusts an xs:date value to a specific time zone, or to no time zone at all; the result is the date in the target time zone that contains the starting instant of the supplied date.
fn:adjust-date-to-timezone ($arg as xs:date?, $timezone as xs:dayTimeDuration?) as xs:date? 2.0
fn:adjust-time-to-timezone ($arg as xs:time?) as xs:time? 2.0 Adjusts an xs:time value to a specific time zone, or to no time zone at all.
fn:adjust-time-to-timezone ($arg as xs:time?, $timezone as xs:dayTimeDuration?) as xs:time? 2.0
fn:current-date() as xs:date 2.0 Returns the current date; subsequent calls within the same program will usually return the same value.
fn:current-dateTime() as xs:dateTimeStamp 2.0 Returns the current date and time (with time zone); subsequent calls within the same program will usually return the same value.
fn:current-time() as xs:time 2.0 Returns the current time; subsequent calls within the same program will usually return the same value.
fn:dateTime($arg1 as xs:date?, $arg2 as xs:time?) as xs:dateTime? 2.0 Returns an xs:dateTime value created by combining an xs:date and an xs:time.
fn:day-from-date($arg as xs:date?) as xs:integer? 2.0 Returns the day component of an xs:date.
fn:day-from-dateTime($arg as xs:dateTime?) as xs:integer? 2.0 Returns the day component of an xs:dateTime.
fn:days-from-duration($arg as xs:duration?) as xs:integer? 2.0 Returns the number of days in a duration.
fn:format-dateTime($value as xs:dateTime?, $picture as xs:string) as xs:string? 3.0 Returns a string containing an xs:dateTime value formatted for display (formerly in XSLT only).
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? 3.0
fn:format-date($value as xs:date?, $picture as xs:string) as xs:string? 3.0 Returns a string containing an xs:date value formatted for display (formerly in XSLT only).
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? 3.0
fn:format-time($value as xs:time?, $picture as xs:string) as xs:string? 3.0 Returns a string containing an xs:time value formatted for display (formerly in XSLT only).
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? 3.0
fn:hours-from-dateTime ($arg as xs:dateTime?) as xs:integer? 2.0 Returns the hours component of an xs:dateTime.
fn:hours-from-duration ($arg as xs:duration?) as xs:integer? 2.0 Returns the number of hours in a duration.
fn:hours-from-time($arg as xs:time?) as xs:integer? 2.0 Returns the hours component of an xs:time.
fn:implicit-timezone() as xs:dayTimeDuration 2.0 Returns the value of the implicit time zone property from the dynamic context.
fn:minutes-from-dateTime ($arg as xs:dateTime?) as xs:integer? 2.0 Returns the minutes component of an xs:dateTime.
fn:minutes-from-duration ($arg as xs:duration?) as xs:integer? 2.0 Returns the number of minutes in a duration.
fn:minutes-from-time($arg as xs:time?) as xs:integer? 2.0 Returns the minutes component of an xs:time.
fn:month-from-date($arg as xs:date?) as xs:integer? 2.0 Returns the month component of an xs:date.
fn:month-from-dateTime ($arg as xs:dateTime?) as xs:integer? 2.0 Returns the month component of an xs:dateTime.
fn:months-from-duration ($arg as xs:duration?) as xs:integer? 2.0 Returns the number of months in a duration.
fn:seconds-from-dateTime ($arg as xs:dateTime?) as xs:decimal? 2.0 Returns the seconds component of an xs:dateTime.
fn:seconds-from-duration ($arg as xs:duration?) as xs:decimal? 2.0 Returns the number of seconds in a duration.
fn:seconds-from-time($arg as xs:time?) as xs:decimal? 2.0 Returns the seconds component of an xs:time.
fn:timezone-from-date($arg as xs:date?) as xs:dayTimeDuration? 2.0 Returns the time zone component of an xs:date.
fn:timezone-from-dateTime($arg as xs:dateTime?) as xs:dayTimeDuration? 2.0 Returns the time zone component of an xs:dateTime.
fn:timezone-from-time($arg as xs:time?) as xs:dayTimeDuration? 2.0 Returns the time zone component of an xs:time.
fn:year-from-date($arg as xs:date?) as xs:integer? 2.0 Returns the year component of an xs:date.
fn:year-from-dateTime ($arg as xs:dateTime?) as xs:integer? 2.0 Returns the year component of an xs:dateTime.
fn:years-from-duration ($arg as xs:duration?) as xs:integer? 2.0 Returns the number of years in a duration.

Files and the Environment

These functions interact with the system beyond the XPath engine itself, such as reading or creating files. Note that XQuery and XSLT do not allow you to read from a file in the same query or stylesheet in which you created the file.

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:available-environment-variables() as xs:string∗ 2.0 Returns a list of environment variable names that are suitable for passing to fn:environment-variable, as a (possibly empty) sequence of strings.
fn:collection($arg as xs:string?) as node()∗ 2.0 Returns a sequence of nodes representing a collection of documents identified by a collection URI; or a default collection if no URI is supplied.
fn:collection() as node()∗ 2.0
fn:default-collation() as xs:string 2.0 Returns the value of the default collation property from the static context.
fn:doc-available($uri as xs:string?) as xs:boolean 2.0 The function returns true if and only if the function call fn:doc($uri) would return a document node. This is useful because it’s generally an error if fn:doc() fails to load a file.
fn:doc($uri as xs:string?) as document-node()? 2.0 Retrieves a document using a URI supplied as an xs:string, and returns the corresponding document node.
fn:environment-variable ($name as xs:string) as xs:string? 2.0 Returns the value of a system environment variable, if it exists.
fn:error() as none 2.0 Calling the fn:error function raises an application-defined error.
fn:error($code as xs:QName) as none 2.0
fn:error($code as xs:QName?, $description as xs:string) as none 2.0
fn:error($code as xs:QName?, $description as xs:string, $error-object as item()∗) as none 2.0
fn:parse-xml($arg as xs:string?) as document-node(element (∗, xs:untyped)) 3.0 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. It was experimental at the time of writing.
fn:parse-xml-fragment ($arg as xs:string?) as document-node(element(∗, xs:untyped)) 3.0 This function takes as input an XML fragment such as an external XML entity, represented as a string, and returns the document node at the root of an XDM tree representing the parsed document. It was experimental at the time of writing.
fn:serialize($arg as item()∗) as xs:string 3.0 This function serializes the supplied input sequence $arg as described in “XSLT and XQuery Serialization 3.0,” returning a string.
fn:serialize($arg as item()∗, $params as element(output:serialization-parameters)?) as xs:string 2.0
fn:trace($value as item()∗, $label as xs:string) as item()∗ 2.0 Provides an execution trace intended to be used in debugging queries.
fn:unparsed-text-available ($href as xs:string?) as xs:boolean 3.0 Determines whether a call with particular arguments would succeed. Provided because errors in evaluating the fn:unparsed-text function are non-recoverable (formerly XSLT only).
fn:unparsed-text-available ($href as xs:string?, $encoding as xs:string) as xs:boolean 3.0
fn:unparsed-text($href as xs:string?) as xs:string? 3.0 Reads an external resource (for example, a file) and returns its contents as a string (formerly in XSLT only).
fn:unparsed-text($href as xs:string?, $encoding as xs:string) as xs:string? 3.0
fn:unparsed-text-lines ($href as xs:string?) as xs:string∗ 3.0 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 file (formerly only in XSLT 2.1).
fn:unparsed-text-lines ($href as xs:string?, $encoding as xs:string) as xs:string∗ 3.0
fn:uri-collection($arg as xs:string?) as xs:anyURI∗ 3.0 Returns a sequence of xs:anyURI values representing the document URIs of the documents in a collection.
fn:uri-collection() as xs:anyURI∗ 3.0

Functions that Operate on Functions

XPath 3, XSLT 3, and XQuery 3 all introduce higher order functions: functions that operate on other functions.

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:filter($f as function(item()) as xs:boolean, $seq as item()∗) as item()∗ 3.0 Returns those items from the sequence $seq for which the supplied function $f returns true.
fn:fold-left($f as function(item()∗, item()) as item()∗, $zero as item()∗, $seq as item()∗) as item()∗ 3.0 Processes the supplied sequence from left to right, applying the supplied function repeatedly to each item in turn, together with an accumulated result value.
fn:fold-right($f as function(item(), item()∗) as item()∗, $zero as item()∗, $seq as item()∗) as item()∗ 3.0 Processes the supplied sequence from right to left, applying the supplied function repeatedly to each item in turn, together with an accumulated result value.
fn:function-arity($func as function(∗)) as xs:integer 3.0 Returns the arity of the function identified by a function item. The arity is the number of arguments a function takes.
fn:function-name($func as function(∗)) as xs:QName? 3.0 Returns the name of the function identified by a function item.
fn:map($f as function(item()) as item()∗, $seq as item()∗) as item()∗ 3.0 Applies the function item $f to every item from the sequence $seq in turn, returning the concatenation of the resulting sequences in order.

Functions that Operate on Items

These functions take one or more XDM values (items) as arguments.

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:deep-equal($parameter1 as item()∗, $parameter2 as item()∗) as xs:boolean 2.0 Returns true if two sequences, treated as trees, have the same structure and values.
fn:deep-equal($parameter1 as item()∗, $parameter2 as item()∗, $collation as xs:string) as xs:boolean 2.0
fn:element-with-id($arg as xs:string∗) as element()∗ 2.0 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.
fn:element-with-id($arg as xs:string∗, $node as node()) as element()∗ 2.0
fn:empty($arg as item()∗) as xs:boolean 2.0 Returns true if the argument is the empty sequence.
fn:exactly-one($arg as item()∗) as item() 2.0 Returns $arg if it contains exactly one item. Otherwise, raises an error.
fn:exists($arg as item()∗) as xs:boolean 2.0 Returns true if the argument is a non-empty sequence.
fn:index-of($seq as xs:anyAtomicType∗, $search as xs:anyAtomicType) as xs:integer∗ 2.0 Returns a sequence of positive integers giving the positions within the sequence $seq of items that are equal to $search.
fn:index-of($seq as xs:anyAtomicType∗, $search as xs:anyAtomicType, $collation as xs:string) as xs:integer∗ 2.0

Numeric Functions

These functions work with numbers; XPath 1 implementations had to convert numbers to and from strings when they were used, but in XPath 2, and especially XQuery and XSLT, you can declare variables and functions to have numeric types and often achieve improvements both in performance and in error reporting.

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:abs($arg as numeric?) as numeric? 2.0 Returns the absolute value of $arg.
fn:avg($arg as xs:anyAtomicType∗) as xs:anyAtomicType? 2.0 Returns the average of the values in the input sequence $arg, that is, the sum of the values divided by the number of values.
fn:ceiling($arg as numeric?) as numeric? 1.0 Rounds $arg up to a whole number.
fn:floor($arg as numeric?) as numeric? 1.0 Rounds $arg down to a whole number.
fn:max($arg as xs:anyAtomicType∗) as xs:anyAtomicType? 2.0 Returns a value that is equal to the highest value appearing in the input sequence.
fn:max($arg as xs:anyAtomicType∗, $collation as xs:string) as xs:anyAtomicType? 2.0
fn:min($arg as xs:anyAtomicType∗) as xs:anyAtomicType? 2.0 Returns a value that is equal to the lowest value appearing in the input sequence.
fn:min($arg as xs:anyAtomicType∗, $collation as xs:string) as xs:anyAtomicType? 2.0
fn:number($arg as xs:anyAtomicType?) as xs:double 1.0 Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double.
fn:number() as xs:double 1.0
fn:round($arg as numeric?) as numeric? 1.0 Rounds a value to a specified number of decimal places, rounding up if two such values are equally near.
fn:round($arg as numeric?, $precision as xs:integer) as numeric? 3.0
fn:round-half-to-even ($arg as numeric?) as numeric? 2.0 Rounds a value to a specified number of decimal places, rounding to make the last digit even if two such values are equally near.
fn:round-half-to-even($arg as numeric?, $precision as xs:integer) as numeric? 2.0
fn:sum($arg as xs:anyAtomicType∗) as xs:anyAtomicType 1.0 Returns a value obtained by adding together the values in $arg.
fn:sum($arg as xs:anyAtomicType∗, $zero as xs:anyAtomicType?) as xs:anyAtomicType? 2.0
math:acos($arg as xs:double?) as xs:double? 3.0 Returns the arc cosine of the argument, the result being in the range zero to +π radians.
math:asin($arg as xs:double?) as xs:double? 3.0 Returns the arc sine of the argument, the result being in the range -π/2 to +π/2 radians.
math:atan2($y as xs:double, $x as xs:double) as xs:double 3.0 Returns the angle in radians subtended at the origin between a line drawn to the point on a plane with coordinates (x, y) and the positive x-axis, the result being in the range -π to +π.
math:atan($arg as xs:double?) as xs:double? 3.0 Returns the arc tangent of the argument, the result being in the range -π/2 to +π/2 radians.
math:cos($θ as xs:double?) as xs:double? 3.0 Returns the cosine of the argument, expressed in radians.
math:exp10($arg as xs:double?) as xs:double? 3.0 Returns the value of 10 to the power of x.
math:exp($arg as xs:double?) as xs:double? 3.0 Returns the value of e to the power of x.
math:log10($arg as xs:double?) as xs:double? 3.0 Returns the base-ten logarithm of the argument.
math:log($arg as xs:double?) as xs:double? 3.0 Returns the natural logarithm (base e) of the argument.
math:pi() as xs:double 3.0 Returns an approximation to the mathematical constant π.
math:pow($x as xs:double?, $y as numeric) as xs:double? 3.0 Returns the result of raising the first argument to the power of the second.
math:sin($θ as xs:double?) as xs:double? 3.0 Returns the sine of the argument, expressed in radians.
math:sqrt($arg as xs:double?) as xs:double? 3.0 Returns the square root of the argument.
math:tan($θ as xs:double?) as xs:double? 3.0 Returns the tangent of the argument, expressed in radians.

Functions that Operate on Nodes

These functions operate on the various XDM node types such as elements, text nodes, and processing instructions, but not on atomic values such as a string or a number.

FUNCTION NAME AND SIGNATURE V DESCRIPTION
document() 1.0 This was replaced by fn:doc() in XPath 2.0.
fn:base-uri($arg as node()?) as xs:anyURI? 2.0 Returns the base URI used for resolving relative URI references; usually this will be the same for every node in a document, but can be different if external XML entities were used.
fn:base-uri() as xs:anyURI? 3.0
fn:data($arg as item()∗) as xs:anyAtomicType∗ 2.0 Takes a sequence of items and returns a sequence of atomic values. The items can be any mix of atomic values and nodes.
fn:data() as xs:anyAtomicType∗ 3.0
fn:document-uri($arg as node()?) as xs:anyURI? 2.0 Returns the URI of the document containing the given node, if it has one and is known.
fn:document-uri() as xs:anyURI? 3.0
fn:generate-id($arg as node()?) as xs:string 2.0 This function returns a string that uniquely identifies a given node, suitable for use as an XML or HTML ID value (originally in XSLT 1.0 and 2.0 only, not XPath or XQuery).
fn:generate-id() as xs:string 3.0
fn:has-children($node as node()?) as xs:boolean 2.0 True if the supplied node has one or more child nodes (of any kind).
fn:id($arg as xs:string∗) as element()∗ 1.0 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.
fn:id($arg as xs:string∗, $node as node()) as element()∗ 1.0
fn:idref($arg as xs:string∗) as node()∗ 2.0 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.
fn:idref($arg as xs:string∗, $node as node()) as node()∗ 2.0
fn:innermost($nodes as node()∗) as node()∗ 2.0 Returns every node within the input sequence that is not an ancestor of another member of the input sequence.
fn:in-scope-prefixes($element as element()) as xs:string∗ 2.0 Returns the prefixes of the in-scope namespaces for an element node.
fn:lang($testlang as xs:string?) as xs:boolean 2.0 Tests whether the language of $node, as specified by xml:lang attributes, is the same as, or is a sublanguage of, the language specified by $testlang.
fn:lang($testlang as xs:string?, $node as node()) as xs:boolean 1.0
fn:local-name($arg as node()?) as xs:string 1.0 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.
fn:local-name() as xs:string 1.0
fn:local-name-from-QName($arg as xs:QName?) as xs:NCName? 2.0 Returns the local part of the supplied QName.
fn:name($arg as node()?) as xs:string 1.0 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.
fn:name() as xs:string 1.0
fn:namespace-uri($arg as node()?) as xs:anyURI 1.0 Returns the namespace URI part of the name of $arg, as an xs:anyURI value.
fn:namespace-uri() as xs:anyURI 1.0
fn:namespace-uri-for-prefix ($prefix as xs:string?, $element as element()) as xs:anyURI? 2.0 Returns the namespace URI of one of the in-scope namespaces for $element, identified by its namespace prefix.
fn:namespace-uri-from-QName($arg as xs:QName?) as xs:anyURI? 2.0 Returns the namespace URI part of the supplied QName.
fn:nilled($arg as node()?) as xs:boolean? 2.0 Returns true for an element that is nilled; that is, for an element with xsi:nilled=”true”.
fn:node-name($arg as node()?) as xs:QName? 2.0 Returns the name of a node, as an xs:QName.
fn:node-name() as xs:QName? 3.0
fn:outermost($nodes as node()∗) as node()∗ 2.0 Returns every node within the input sequence that has no ancestor that is itself a member of the input sequence.
fn:path($arg as node()?) as xs:string? 3.0 Returns a path expression that can be used to select the supplied node relative to the root of its containing document.
fn:path() as xs:string? 3.0
fn:root($arg as node()?) as node()? 2.0 Returns the root of the tree to which $arg belongs. This will usually, but not necessarily, be a document node.
fn:root() as node() 2.0
fn:static-base-uri() as xs:anyURI? 2.0 Returns the value of the Base URI property from the static context.

Functions that Operate on QNames

A QName is a qualified name: a name that has an optional prefix associated with an XML namespace.

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:prefix-from-QName($arg as xs:QName?) as xs:NCName? 2.0 Returns the prefix component of the supplied QName.
fn:QName($paramURI as xs:string?, $paramQName as xs:string) as xs:QName 2.0 Constructs an xs:QName value given a namespace URI and a lexical QName.
fn:resolve-QName($qname as xs: string?, $element as element()) as xs:QName? 2.0 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.

Functions on Sequences

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:count($arg as item()∗) as xs:integer 1.0 Returns the number of items in a sequence.
fn:distinct-values($arg as xs:anyAtomicType∗) as xs:anyAtomicType∗ 2.0 Returns the values that appear in a sequence, with duplicates eliminated. Also available in some XPath 1.0 implementations.
fn:distinct-values($arg as xs:anyAtomicType∗, $collation as xs:string) as xs:anyAtomicType∗ 2.0
fn:head($arg as item()∗) as item()? 3.0 Returns the first item in a sequence.
fn:insert-before($target as item()∗, $position as xs:integer, $inserts as item()∗) as item()∗ 2.0 Returns a new sequence made by inserting an item or a sequence of items at a given position within an existing sequence.
fn:last() as xs:integer 1.0 Returns the context size from the dynamic context.
fn:map-pairs($f as function(item(), item()) as item()∗, $seq1 as item()∗, $seq2 as item()∗) as item()∗ 3.0 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.
fn:one-or-more($arg as item()∗) as item()+ 2.0 Returns $arg if it contains one or more items. Otherwise, raises an error.
fn:position() as xs:integer 1.0 Returns the context position from the dynamic context.
fn:remove($target as item()∗, $position as xs:integer) as item()∗ 2.0 Returns a new sequence containing all the items of $target, except the item at position $position.
fn:reverse($arg as item()∗) as item()∗ 2.0 Returns a new sequence with the items in the reverse order.
fn:subsequence($sourceSeq as item()∗, $startingLoc as xs:double) as item()∗ 2.0 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.
fn:subsequence($sourceSeq as item()∗, $startingLoc as xs:double, $length as xs:double) as item()∗ 2.0
fn:tail($arg as item()∗) as item()∗ 3.0 Returns all but the first item in a sequence.
fn:unordered($sourceSeq as item()∗) as item()∗ 2.0 Returns the items of $sourceSeq in an implementation-dependent order.
fn:zero-or-one($arg as item()∗) as item()? 2.0 Returns $arg if it contains zero or one items. Otherwise, raises an error.

Functions that Operate on Strings and URIs

A string is just a sequence of zero or more characters. A URI, or Uniform Resource Identifier, is the more general name for URLs or web addresses. URIs and their more modern international counterparts, IRIs, are a separate type from strings, although you can convert between them.

Most string operations can also take a URI identifying a collation. A collation is a system-specific object that says how to sort characters: whether upper and lower case characters are considered different; whether accented characters like é or ø sort before, together with, or after their unaccented counterparts; and where letters like æ and œ fit into the alphabet, as all these details vary from culture to culture and in some cases depending on purpose.

FUNCTION NAME AND SIGNATURE V DESCRIPTION
fn:analyze-string($input as xs:string?, $pattern as xs:string) as element(fn:analyze-string-result) 3.0 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. In the case of matched substrings, determines which substrings matched each capturing group in the regular expression.
fn:analyze-string($input as xs:string?, $pattern as xs:string, $flags as xs:string) as element (fn:analyze-string-result) 3.0
fn:codepoint-equal($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:boolean? 2.0 Returns true if two strings are equal, considered codepoint-by-codepoint.
fn:codepoints-to-string ($arg as xs:integer∗) as xs:string 2.0 Creates an xs:string from a sequence of codepoints expressed as integers.
fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer? 2.0 Returns -1, 0, or 1, depending on whether $comparand1 collates before, equal to, or after $comparand2 according to the rules of a selected collation.
fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer? 2.0
fn:concat($arg1 as xs:anyAtomicType?, $arg2 as xs:anyAtomicType?, ...) as xs:string 1.0 Returns a new string made by joining together all the strings given as arguments. See also string-join().
fn:contains($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean 1.0 Returns true if the string $arg1 contains $arg2 as a substring, taking collations into account.
fn:contains($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean 1.0
fn:encode-for-uri($uri-part as xs:string?) as xs:string 2.0 Encodes reserved characters in a string that is intended to be used in the path segment of a URI.
fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean 2.0 Returns true if the string $arg1 contains $arg2 as a trailing substring, taking collations into account.
fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean 2.0
fn:escape-html-uri($uri as xs:string?) as xs:string 2.0 Escapes a URI in the same way that HTML user agents handle attribute values expected to contain URIs.
fn:format-integer($value as xs:integer?, $picture as xs:string) as xs:string 3.0 Converts an integer to a string representation according to a given picture string (that is, a format), using the conventions of a given natural language if specified.
fn:format-integer($value as xs:integer?, $picture as xs:string, $language as xs:string) as xs:string 3.0
fn:format-number($value as numeric?, $picture as xs:string) as xs:string 2.0 Converts a number to a string representation according to a given picture string (that is, a format), using the conventions of a given natural language if specified (originally only in XSLT).
fn:format-number($value as numeric?, $picture as xs:string, $decimal-format-name as xs:string) as xs:string 3.0
fn:iri-to-uri($iri as xs:string?) as xs:string 2.0 Converts a string containing an IRI into a URI according to the rules of IETF RFC 3987, the specification for Internationalized Resource Identifiers (IRIs). See http://www.ietf.org/rfc/rfc3987.txt
fn:lower-case($arg as xs:string?) as xs:string 2.0 Converts a string to lowercase.
fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean 2.0 True if the supplied string matches a given regular expression.
fn:matches($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:boolean 2.0
fn:normalize-space($arg as xs:string?) as xs:string 1.0 Returns the value of $arg with leading and trailing whitespace removed, and sequences of internal whitespace reduced to a single space character.
fn:normalize-space() as xs:string 1.0
fn:normalize-unicode($arg as xs:string?) as xs:string 2.0 Returns the value of $arg after applying Unicode normalization.
fn:normalize-unicode($arg as xs:string?, $normalizationForm as xs:string) as xs:string 2.0
fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string) as xs:string 2.0 Returns a string produced from the input string by replacing any substrings that match a given regular expression with a supplied replacement string.
fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string, $flags as xs:string) as xs:string 2.0
fn:resolve-uri($relative as xs:string?) as xs:anyURI? 2.0 Resolves a relative IRI reference against an absolute IRI. An IRI is an Internationalized version of a URI; the function name has “uri” in it because it predates the IRI specification.
fn:resolve-uri($relative as xs:string?, $base as xs:string) as xs:anyURI? 2.0
fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean 1.0 Returns true if the string $arg1 contains $arg2 as a leading substring, taking collations into account.
fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean 1.0
fn:string($arg as item()?) as xs:string 1.0 Constructs a new string.
fn:string() as xs:string 1.0
fn:string-join($arg1 as xs:string∗, $arg2 as xs:string) as xs:string 2.0 Returns a single new string made by joining the given strings together, but putting $arg2 (if given) between the strings.
fn:string-join($arg1 as xs:string∗) as xs:string 3.0
fn:string-length($arg as xs:string?) as xs:integer 1.0 Returns the number of characters in a given string.
fn:string-length() as xs:integer 1.0
fn:string-to-codepoints($arg as xs:string?) as xs:integer∗ 2.0 Returns the sequence of integer codepoints corresponding to each character in turn in the given string.
fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?) as xs:string 1.0 Returns the part of $arg1 that follows the first occurrence of $arg2, taking collations into account.
fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string 2.0
fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?) as xs:string 1.0 Returns the part of $arg1 that precedes the first occurrence of $arg2, taking collations into account.
fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string 2.0
fn:substring($sourceString as xs:string?, $start as xs:double) as xs:string 1.0 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. The first character is numbered one, not zero.
fn:substring($sourceString as xs:string?, $start as xs:double, $length as xs:double) as xs:string 1.0
fn:tokenize($input as xs:string?, $pattern as xs:string) as xs:string∗ 2.0 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.
fn:tokenize($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:string∗ 2.0
fn:translate($arg as xs:string?, $mapString as xs:string, $transString as xs:string) as xs:string 1.0 Returns the value of $arg modified by replacing every character in $mapString with the corresponding character in $transString, or deleting the character if $mapString is longer than $transString.
fn:upper-case($arg as xs:string?) as xs:string 2.0 Converts a string to uppercase.

Functions to Construct Objects by XSD Type

These functions construct objects of the named types. You may need to bind the xs namespace prefix to the URI http://www.w3.org/2001/XMLSchema (this is already done for you in XQuery).

FUNCTION NAME AND SIGNATURE V DESCRIPTION
xs:anyURI($arg as xs:anyAtomicType?) as xs:anyURI? 2.0 Constructs a new object of XML Schema type xs:anyURI.
xs:base64Binary($arg as xs:anyAtomicType?) as xs:base64Binary? 2.0 Constructs a new object of XML Schema type xs:base64Binary.
xs:boolean($arg as xs:anyAtomicType?) as xs:boolean? 2.0 Constructs a new object of XML Schema type xs:boolean.
xs:byte($arg as xs:anyAtomicType?) as xs:byte? 2.0 Constructs a new object of XML Schema type xs:byte.
xs:date($arg as xs:anyAtomicType?) as xs:date? 2.0 Constructs a new object of XML Schema type xs:date.
xs:dateTime($arg as xs:anyAtomicType?) as xs:dateTime? 2.0 Constructs a new object of XML Schema type xs:dateTime.
xs:dateTimeStamp($arg as xs:anyAtomicType?) as xs:dateTimeStamp? 3.0 Constructs a new object of XML Schema type xs:dateTimeStamp.
xs:dayTimeDuration($arg as xs:anyAtomicType?) as xs:dayTimeDuration? 2.0 Constructs a new object of XML Schema type xs:dayTimeDuration.
xs:decimal($arg as xs:anyAtomicType?) as xs:decimal? 2.0 Constructs a new object of XML Schema type xs:decimal.
xs:double($arg as xs:anyAtomicType?) as xs:double? 2.0 Constructs a new object of XML Schema type xs:double.
xs:duration($arg as xs:anyAtomicType?) as xs:duration? 2.0 Constructs a new object of XML Schema type xs:duration.
xs:ENTITY($arg as xs:anyAtomicType?) as xs:ENTITY? 2.0 Constructs a new object of XML Schema type xs:ENTITY.
xs:float($arg as xs:anyAtomicType?) as xs:float? 2.0 Constructs a new object of XML Schema type xs:float.
xs:gDay($arg as xs:anyAtomicType?) as xs:gDay? 2.0 Constructs a new object of XML Schema type xs:gDay.
xs:gMonth($arg as xs:anyAtomicType?) as xs:gMonth? 2.0 Constructs a new object of XML Schema type xs:gMonth.
xs:gMonthDay($arg as xs:anyAtomicType?) as xs:gMonthDay? 2.0 Constructs a new object of XML Schema type xs:gMonthDay.
xs:gYear($arg as xs:anyAtomicType?) as xs:gYear? 2.0 Constructs a new object of XML Schema type xs:gYear.
xs:gYearMonth($arg as xs:anyAtomicType?) as xs:gYearMonth? 2.0 Constructs a new object of XML Schema type xs:gYearMonth.
xs:hexBinary($arg as xs:anyAtomicType?) as xs:hexBinary? 2.0 Constructs a new object of XML Schema type xs:hexBinary.
xs:ID($arg as xs:anyAtomicType?) as xs:ID? 2.0 Constructs a new object of XML Schema type xs:ID.
xs:IDREF($arg as xs:anyAtomicType?) as xs:IDREF? 2.0 Constructs a new object of XML Schema type xs:IDREF.
xs:int($arg as xs:anyAtomicType?) as xs:int? 2.0 Constructs a new object of XML Schema type xs:int.
xs:integer($arg as xs:anyAtomicType?) as xs:integer? 2.0 Constructs a new object of XML Schema type xs:integer.
xs:language($arg as xs:anyAtomicType?) as xs:language? 2.0 Constructs a new object of XML Schema type xs:language.
xs:long($arg as xs:anyAtomicType?) as xs:long? 2.0 Constructs a new object of XML Schema type xs:long.
xs:Name($arg as xs:anyAtomicType?) as xs:Name? 2.0 Constructs a new object of XML Schema type xs:Name.
xs:NCName($arg as xs:anyAtomicType?) as xs:NCName? 2.0 Constructs a new object of XML Schema type xs:NCName.
xs:negativeInteger($arg as xs:anyAtomicType?) as xs:negativeInteger? 2.0 Constructs a new object of XML Schema type xs:negativeInteger.
xs:NMTOKEN($arg as xs:anyAtomicType?) as xs:NMTOKEN? 2.0 Constructs a new object of XML Schema type xs:NMTOKEN.
xs:nonNegativeInteger ($arg as xs:anyAtomicType?) as xs:nonNegativeInteger? 2.0 Constructs a new object of XML Schema type xs:nonNegativeInteger.
xs:nonPositiveInteger ($arg as xs:anyAtomicType?) as xs:nonPositiveInteger? 2.0 Constructs a new object of XML Schema type xs:nonPositiveInteger.
xs:normalizedString($arg as xs:anyAtomicType?) as xs:normalizedString? 2.0 Constructs a new object of XML Schema type xs:normalizedString.
xs:positiveInteger($arg as xs:anyAtomicType?) as xs:positiveInteger? 2.0 Constructs a new object of XML Schema type xs:positiveInteger.
xs:QName($arg as xs:anyAtomicType) as xs:QName? 2.0 Constructs a new object of XML Schema type xs:QName.
xs:short($arg as xs:anyAtomicType?) as xs:short? 2.0 Constructs a new object of XML Schema type xs:short.
xs:string($arg as xs:anyAtomicType?) as xs:string? 2.0 Constructs a new object of XML Schema type xs:string.
xs:time($arg as xs:anyAtomicType?) as xs:time? 2.0 Constructs a new object of XML Schema type xs:time.
xs:token($arg as xs:anyAtomicType?) as xs:token? 2.0 Constructs a new object of XML Schema type xs:token.
xs:unsignedByte($arg as xs:anyAtomicType?) as xs:unsignedByte? 2.0 Constructs a new object of XML Schema type xs:unsignedByte.
xs:unsignedInt($arg as xs:anyAtomicType?) as xs:unsignedInt? 2.0 Constructs a new object of XML Schema type xs:unsignedInt.
xs:unsignedLong($arg as xs:anyAtomicType?) as xs:unsignedLong? 2.0 Constructs a new object of XML Schema type xs:unsignedLong.
xs:unsignedShort($arg as xs:anyAtomicType?) as xs:unsignedShort? 2.0 Constructs a new object of XML Schema type xs:unsignedShort.
xs:untypedAtomic($arg as xs:anyAtomicType?) as xs:untypedAtomic? 2.0 Constructs a new object of XML Schema type xs:untypedAtomic.
xs:yearMonthDuration($arg as xs:anyAtomicType?) as xs:yearMonthDuration? 2.0 Constructs a new object of XML Schema type xs:yearMonthDuration.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.108.86