XPath/XQuery count function

Summary

Returns the number of items in a sequence.

Signature

fn:count(
$arg as item()*
) as xs:integer

Properties

This function is deterministic, context-independent, and focus-independent.

Rules

The function returns the number of items in the value of $arg.

Examples

let $seq1 := ($item1, $item2)

let $seq2 := (98.5, 98.3, 98.9)

let $seq3 := ()

The expression fn:count($seq1) returns 2.

The expression fn:count($seq3) returns 0.

The expression fn:count($seq2) returns 3.

The expression fn:count($seq2[. > 100]) returns 0.

The expression fn:count([]) returns 1.

The expression fn:count([1,2,3]) returns 1.

Notes

Returns 0 if $arg is the empty sequence.

Example in XMLSpy

An example of the Count function used in XPath and XQuery