MarkLogic 9 Product Documentation
fn:min

fn:min(
   $arg as xs:anyAtomicType*,
   [$collation as xs:string]
) as xs:anyAtomicType?

Summary

Selects an item from the input sequence $arg whose value is less than or equal to the value of every other item in the input sequence. If there are two or more such items, then the specific item whose value is returned is implementation dependent.

The following rules are applied to the input sequence:

The items in the resulting sequence may be reordered in an arbitrary order. The resulting sequence is referred to below as the converted sequence.This function returns an item from the converted sequence rather than the input sequence.

If the converted sequence is empty, the empty sequence is returned.

All items in $arg must be numeric or derived from a single base type for which the le operator is defined. In addition, the values in the sequence must have a total order. If date/time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for purposes of comparison. Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.

If any of these conditions is not met, then a type error is raised [err:FORG0006].

If the converted sequence contains the value NaN, the value NaN is returned.

If the items in the value of $arg are of type xs:string or types derived by restriction from xs:string, then the determination of the item with the largest value is made according to the collation that is used. If the type of the items in $arg is not xs:string and $collation is specified, the collation is ignored.

The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations.

Otherwise, the result of the function is the result of the expression:

   if (every $v in $c satisfies $c[1] le $v)
   then $c[1]
   else fn:min(fn:subsequence($c, 2))

evaluated with $collation as the default collation if specified, and with $c as the converted sequence.

For detailed type semantics, see Section 7.2.10 The fn:min, fn:max, fn:avg, and fn:sum functions[FS].

Notes:

If the converted sequence contains exactly one value then that value is returned.

The default type when the fn:min function is applied to xs:untypedAtomic values is xs:double. This differs from the default type for operators such as gt, and for sorting in XQuery and XSLT, which is xs:string.

Parameters
$arg The sequence of values whose minimum will be returned.
collation The optional name of a valid collation URI. For information on the collation URI syntax, see the Search Developer's Guide.

Example

fn:min((3,4,5)) returns 3.

fn:min((5, 5.0e0)) returns 5.0e0.

fn:min((3,4,"Zero")) raises a type error [err:FORG0006].

fn:min(xs:float(0.0E0), xs:float(-0.0E0) can return
either positive or negative zero.
[XML Schema Part 2: Datatypes Second Edition] does
not distinguish between the values positive zero
and negative zero.
The result is implementation dependent.

fn:min((fn:current-date(), xs:date("2001-01-01")))
typically returns xs:date("2001-01-01").

fn:min(("a", "b", "c")) returns "a" under a
typical default collation.
Powered by MarkLogic Server | Terms of Use | Privacy Policy