saxon:highest

Finds the items having the highest value for some expression.

highest($input as item()*) ➔ item()*

Arguments

 

$input

item()*

The input sequence

Result

item()*

highest($input as item()*, $key as function(item()) as xs:anyAtomicType?) ➔ item()*

Arguments

 

$input

item()*

The input sequence

 

$key

function(item()) as xs:anyAtomicType?

Function to compute the sort key

Result

item()*

Namespace

http://saxon.sf.net/

Saxon availability

Requires Saxon-PE or Saxon-EE.

Notes on the Saxon implementation

Available since before Saxon 8.0. Changed in Saxon 9.5 to take a function rather than an expression as the second argument. Changed in 9.9 to allow the sort key to be an empty sequence, and to define the result of edge cases more precisely.

Details

This function returns the item or items from the input sequence that have the highest value for the function $key. If the second argument is omitted, it defaults to the function fn:data#1, that is, it atomizes the item from the input sequence.

The $key function is evaluated for each item in $input in turn, with that item supplied as the parameter to the function. Any items for which the sort key evaluates to an empty sequence or to NaN are ignored. If the input sequence is empty, the result is an empty sequence. If several items have the highest value, the result sequence contains them all, retaining the original order.

Any computed key that is of type xs:untypedAtomic is converted to xs:double.

Strings are compared using the default collation from the static context.

An error occurs if any key belongs to an unordered type (such as xs:QName) or if two keys belong to types that are not comparable (for example xs:integer and xs:string).

Example: saxon:highest(sale, function($x){$x/@price * $x/@qty}) will evaluate price times quantity for each child <sale> element, and return the element or elements for which this has the highest value.

See also:

saxon:lowest()