xf:min

Finds the minimum 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.

Signatures

xf:min(integer* $integer-var) —> xs:anySimpleType?

Arguments

Data Type
Argument
Description

integer*

$integer-var

Represents the sequence to evaluate.

Returns

Returns the number with the lowest value from the sequence passed into $item-var.

Examples

Simple

Invoking xf:min(("3","1","2")) returns the value of 1, as shown in the following example query:

<result>{xf:min(("3","1","2"))}</result> 

The preceding query generates the following result:

<result>1</result> 

Empty Sequences

Invoking xf:min((1,(),6,2,9)) returns the value of 1, as shown in the following example query:

<result>{xf:min((1,(),6,2,9))}</result> 

The preceding query generates the following result:

<result>1</result> 

Note: Instances of the empty sequence () are ignored.

Nodes

Invoking the following query returns the value of 2, the lowest number in the sequence, 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:min(($x,$y,$z))}</result> 

The preceding query generates the following result:

<result>100</result> 

In this example, the value of the nodes are extracted before the comparison to determine the minimum 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: 100 is reported as the minimum value because the ASCII value of the character 1 is less than the ASCII value of the character 5, the first character in the string: 50. 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:min 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:min(bea-xf:integer-sequence(($x,$y,$z)))}</result> 

The preceding query generates the following result:

<result>2</result> 

Related Topics

W3C min function description.

BEA bea-xf:integer-sequence function description.