max function

The fn:max function returns the maximum of the values in a sequence.

Syntax

Read syntax diagramSkip visual syntax diagramfn:max( sequence-expression)
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 the items in the input sequence must be convertible by promotion or subtype substitution to a common type that supports the ge operator. The maximum 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 maximum 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 maximum 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.

Example

The following function returns the maximum of the sequence (500, 1.0E2, 40.5).

fn:max((500, 1.0E2, 40.5))

The values are promoted to the xs:double data type. The function returns the xs:double value 5.0E2, which is serialized as "500".