New functions
A number of new experimental functions become available if XPath 4.0 is enabled.
A few of these functions are made available in Saxon in two forms. They are available unconditionally
in the Saxon namespace; and if 4.0 extensions are available then they are also available in the
standard fn
(or where appropriate, the map
or array
) namespace.
Returns true if every item in $input
satisfies the predicate.
For example, fn:all(*, ->{boolean(self::para)})
returns true if every child element of the
context item is a para
element.
The second argument may be omitted and defaults to fn:identity#1
, so
fn:all((1=1, 2=2, 3=4))
returns false.
Returns true if the values in $values
are all different (that is, if no two values are equal).
A collation may be supplied as the second argument.
Returns true if the values in $values
are all equal. A collation may be supplied as the second argument.
Splits a string into a sequence of single-character strings.
For example, fn:characters("red")
returns ("r", "e", "d")
.
Tests whether the first sequence contains the second as a subsequence; items are compared using the supplied comparison function, which can be defaulted.
fn:ends-with-sequence( $input as item()*, $subsequence as item()*, $compare as function(item(), item()) as xs:boolean := fn:deep-equal#2 ) as xs:booleanTests whether the first sequence contains the second as a final subsequence; items are compared using the supplied comparison function, which can be defaulted.
fn:expanded-QName( $qname as xs:QName? ) as xs:string?Converts a QName into Q{uri}local
notation.
Returns the last item in a sequence.
fn:highest( $input as item()*, $collation as xs:string? := fn:default-collation(), $key as function(item()) as xs:anyAtomicType* := fn:identity#1 ) as item()*Returns those items from the input sequence having the highest value for the supplied function, strings being compared using the supplied collation (which defaults to the default collation).
For example, fn:highest(//employee, (), ->{number(@salary)})
returns those
employees having the highest salary.
Returns the value of the argument, unchanged. Useful in situations where a function must be supplied, but the desired action is to do nothing.
fn:index-where( $input as item()*, $predicate as function(item()) as xs:boolean ) as xs:integer*Returns the positions of the items in the input sequence that satisfy the supplied predicate.
For example, fn:index-where(("red", "pink", "white", "black"), ->{contains(., "e")})
returns (1, 3)
.
Inserts a copy of $separator
between adjacent items in the input sequence.
Returns the in-scope namespaces of an element as a map from prefixes to URIs.
fn:is-NaN( $value as xs:anyAtomicType ) as xs:booleanReturns true if the supplied value is the xs:float
or xs:double
value NaN.
Returns the items in the input sequence that follow the first one that satisfies the supplied predicate.
fn:items-at( $input as item()*, $at as xs:integer* ) as item()*Returns the items at the given positions in the input sequence. For example fn:items-at(21 to 30, (3, 2, 1))
returns (23, 22, 21)
.
Returns the items in the input sequence that precede the first one that satisfies the supplied predicate.
fn:items-ending-where( $input as item()*, $predicate as function(item()) as xs:boolean ) as item()*Returns the items in the input sequence up to and including the first one that satisfies the supplied predicate.
fn:items-starting-where( $input as item()*, $predicate as function(item()) as xs:boolean ) as item()*Returns the items in the input sequence starting with the first one that satisfies the supplied predicate.
fn:iterate-while( $input as item()*, $predicate as function(item()*) as xs:boolean, $action as function(item()*) as item()* ) as item()*Applies the $action
function to the $input
repeatedly so long as the $predicate
function returns true. For example fn:iterate-while(2, ->{. lt 20}, ->{.*.})
returns 16.
Returns those items from the input sequence having the lowest value for the supplied function, strings being compared using the supplied collation (which defaults to the default collation).
For example, fn:lowest(//employee, (), ->{number(@salary)})
returns those
employees having the lowest salary.
Returns an arity-2 function corresponding to a supplied binary operator, for example fn:op("is")
returns function($x, $y){$x is $y}
.
Wraps an arbitrary sequence of items as a parcel: a parcel is a map with a single entry,
whose key is the string "value"
and whose value is the wrapped sequence. Parcels are
useful because they enable an array to be treated as a sequence of items, by wrapping each member of the
array as a parcel.
Parses an HTML5 document (supplied as a string) using the HTML5 parsing algorithm, returning
the result as an XDM document. In SaxonJ this is implemented using validator.nu
; in SaxonCS the
implementation uses AngleSharp
.
Parses a string as a QName (using namespace bindings from the static context where necessary). The string may
take one of the formats "local"
, "prefix:local"
, or "Q{uri}local"
.
Decomposes a composite "atomic" value into its parts, in the form of a map. For example, an xs:dateTime
value is decomposed into year, month, day, hour, minute, second, and timezone. Other values that are decomposable include
xs:date
, xs:time
, xs:duration
, xs:QName
, and xs:anyURI
.
For values that are not decomposable, the resulting map contains a single entry whose key is "value" and whose corresponding
value is the input value.
Dropped from Saxon 12.
fn:replicate( $input as item()*, $count as xs:nonNegativeInteger ) as item()*Produces a sequence containing $count
copies of $input
.
Selects items from an input sequence, starting at $start
(default 1), ending at $end
(defaulting
to the length of the sequence), and stepping by $step
(defaulting to 1). If $start
or $end
is negative, counting is from the end of the sequence. If $step
is negative, the sequence runs backwards.
Returns true if at least one item in $input
satisfies the predicate.
The second argument may be omitted and defaults to fn:identity#1
, so
fn:some((1=1, 2=2, 3=4))
returns true.
Tests whether the first sequence contains the second as a leading subsequence; items are compared using the supplied comparison function, which can be defaulted.
fn:trunk( $input as item()* ) as item()*Returns all items in a sequence except the last.
fn:unparcel($parcel as record(value, *)) as item()*Reverses the effect of the fn:parcel()
function. (Equivalent to $parcel?value
.)
Returns true if the size of the array is zero.
array:exists( $array as array(*) ) as xs:booleanReturns true if the size of the array is not zero.
array:foot( $array as array(*) ) as item()*Returns the last member of an array.
array:index-where( $array as array(*), $predicate as function(item()*) as xs:boolean ) as xs:integer*Returns the integer positions of members of the array for which the predicate returns true.
array:members($array as array(*)) as record(value)*Accepts an array as input, and turns it into a sequence of parcels: the inverse of the array:of()
function.
Accepts a sequence of parcels (as produced by the fn:parcel()
function), and returns an array
whose members are the sequences obtained by applying fn:unparcel()
to each parcel in turn.
Returns an array containing all members of the input array except the last.
map:build( $input as item()*, $key as function(item()) as xs:anyAtomicType? := fn:identity#1, $value as function(item()) as item()* := fn:identity#1, $combine as function(item()*, item()*) as item()* := fn:op(',') ) as map(*)Builds a map that indexes the $input
sequence. For each item in $input
,
a map entry is generated, with its key computed using the $key
function, and the
corresponding value computed using the $value
function. If there are duplicate keys,
the values are combined using the $combine
function.
Accepts a map as input, and turns it into a sequence of singleton maps representing the key-value pairs contained in the map.
Equivalent to map:for-each($map, ->($k, $v){map{$k : $v}})
.
Accepts a map as input, and returns a new map containing those entries from the original map that satisfy the predicate function.
map:key-value-pairs($map as map(*)) as record(key as xs:anyAtomicType, value as item()*)*Accepts a map as input, and turns it into a sequence of maps representing the key-value pairs contained in the map.
Equivalent to map:for-each($map, ->($k, $v){map{"key":$k, "value":$v}})
. This differs from
map:entries
in that each entry in the input map is turned into a map with two entries, named "key"
and "value", rather than a singleton map with one entry.