min function
The fn:min function returns the minimum of the values in a sequence.
Syntax
- sequence-expression
- A sequence that contains items of any of the following atomic
types, or an empty sequence:
- xs:float
- xs:double
- xs:decimal
- xs:integer
- xs:string
- xs:date
- xs:time
- xs:dateTime
- xdt:untypedAtomic
- xdt:dayTimeDuration
- xdt:yearMonthDuration
- A type that is derived from any of the previously listed types
Input items of type xdt:untypedAtomic are cast to xs:double. After this casting, all of the items in the input sequence must be convertible by promotion or subtype substitution to a common type that supports the le operator. The minimum value is computed in this common type. For example, if the input sequence contains items of type money (derived from xs:decimal) and stockprice (derived from xs:float), the minimum is computed in the type xs:float.
Before date, time, or dateTime values are compared, they are adjusted to a common timezone. Datetime values without an explicit timezone component use the implicit timezone, which is UTC.
String values are compared using the default collation.
Returned value
If sequence-expression is not the empty sequence, the returned value is the minimum of the values in sequence-expression. The data type of the returned value is the same as the data type of the items in sequence-expression, or the common data type to which the items in sequence-expression are promoted.
If sequence-expression is the empty sequence, the empty sequence is returned. If the sequence includes the value NaN, NaN is returned.
Examples
Example with numeric arguments: The following function returns the minimum of the sequence (500, 1.0E2, 40.5):
fn:min((500, 1.0E2, 40.5))The values are promoted to the xs:double data type. The function returns the xs:double value 4.05E1, which is serialized as "40.5".
Example with string arguments: The following function returns the minimum of the sequence ("x", "y", "Z") using the default collation. Assume that the default collation sorts lowercase alphabetic characters before uppercase alphabetic characters.
fn:min(("x", "y", "Z"))The returned value is "x".
