Finds the maximum value in a sequence.
If the value of $item-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.
xf:max(integer* $integer-var) —> xs:anySimpleType?
Returns the number with the highest value from the sequence passed into $item-var.
Invoking xf:max(("3","1","2")) returns the value of 3, as shown in the following example query:
<result>{xf:max(("3","1","2"))}</result>
The preceding query generates the following result:
<result>3</result>
Invoking xf:max((1,(),6,2,9)) returns the value of 9, as shown in the following example query:
<result>{xf:max((1,(),6,2,9))}</result>
The preceding query generates the following result:
<result>9</result>
Note: Instances of the empty sequence () are ignored.
Invoking the following query returns the value of 100, as shown in the following example query:
let $x := <a>100</a>
let $y := <b>2</b>
let $z := <c>50</c>
return <result>{xf:max(($x,$y,$z))}</result>
The preceding query generates the following result:
<result>50</result>
In this example, the value of the nodes are extracted before the comparison to determine the maximum number is done—as if the data function had been invoked on each node in the sequence before the comparison. However, the string values of the nodes are extracted and compared and not the integer values of the node. In the preceding query, the string: 50 is reported as the maximum value because the ASCII value of the character 5 is greater than the ASCII value of the character 1, the first character in the string: 100. To compare the integer values of the nodes instead, first convert the node sequences to integers using the bea-xf:integer-sequence function and then invoke the xf:max function, as shown in the following example query:
let $x := <a>100</a> let $y := <b>2</b> let $z := <c>50</c> return <result>{xf:max(bea-xf:integer-sequence(($x,$y,$z)))}</result>
The preceding query generates the following result:
<result>100</result>
W3C max function description.
BEA bea-xf:integer-sequence function description.