New functions
A number of new experimental functions become available if XPath 4.0 is enabled.
Many of these functions are made available in Saxon 11 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.
fn:all($sequence as item()*, $predicate as function(item()) as xs:boolean) as xs:integer*
Returns true if every item in $sequence
satisfies the predicate.
For example, fn:all(*, ->{boolean(self::para)})
returns true if every child element of the
context item is a para
element.
fn:characters($string as xs:string?) as xs:string*
Splits a string into a sequence of single-character strings.
For example, fn:characters("red")
returns ("r", "e", "d")
.
fn:highest($sequence as item()*) as item()*
Equivalent to fn:highest($sequence, default-collation())
.
fn:highest($sequence as item()*, $collation as xs:string) as item()*
Equivalent to fn:highest($sequence, (), fn:data#1)
.
fn:highest($sequence as item()*, $collation as xs:string?, $key as function(item()) as xs:anyAtomicType) 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.
fn:identity($input as item()*) as item()*
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:in-scope-namespaces($in as element()) as map(xs:string, xs:string)
Returns the in-scope namespaces of an element as a map from prefixes to URIs.
fn:index-where($sequence 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)
.
fn:is-NaN($in as xs:anyAtomicType) as xs:boolean
Returns true if the supplied value is the xs:float
or xs:double
value NaN.
fn:items-after($sequence as item()*, $predicate as function(item()) as xs:boolean) as item()*
Returns the items in the input sequence that follow the first one that satisfies the supplied predicate.
fn:items-before($sequence as item()*, $predicate as function(item()) as xs:boolean) as item()*
Returns the items in the input sequence that precede the first one that satisfies the supplied predicate.
fn:items-from($sequence 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:items-until($sequence 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:lowest($sequence as item()*) as item()*
Equivalent to fn:lowest($sequence, default-collation())
.
fn:lowest($sequence as item()*, $collation as xs:string?) as item()*
Equivalent to fn:lowest($sequence, (), fn:data#1)
.
fn:lowest($sequence as item()*, $collation as xs:string?, function(item()) as xs:anyAtomicType) as item()*
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.
fn:parcel($sequence as item()*) as record(value)
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.
fn:parts($in as item()) as map(xs:string, xs:anyAtomicType)
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.
fn:range()
Not documented because the specification is likely to change.
fn:slice($input as item()*, $start as xs:integer?, $end as xs:integer?, $step as xs:integer?) as item()*
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.
fn:some($sequence as item()*, $predicate as function(item()) as xs:boolean) as xs:boolean
Returns true if at least one item in $sequence
satisfies the predicate.
fn:unparcel($parcel as record(value, *)) as item()*
Reverses the effect of the fn:parcel()
function. (Equivalent to $parcel?value
.)
array:members(array(*)) as record(value)*
Accepts an array as input, and turns it into a sequence of parcels: the inverse of the array:of()
function.
array:of(record(value, *)*) as array(*)
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.
map:entries(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}})
.