index-of function

The fn:index-of function returns the positions where an item appears in a sequence.

Syntax

Read syntax diagramSkip visual syntax diagramfn:index-of( sequence-expression, search-value)
sequence-expression
Any sequence of atomic types, or the empty sequence.
search-value
The value to find in sequence-expression.

Returned value

The returned value is a sequence of xs:integer values that represent the positions of items in sequence-expression that match search-value when compared by using the rules of the eq operator using the default collation. Items that cannot be compared because the eq operator is not defined for their types are considered to not match search-value, and therefore the positions are not returned. The first item in a sequence has the position 1.

The function returns an empty sequence if search-value does not match any items in sequence-expression , or if sequence-expression is an empty sequence.

Example

The following function returns the positions where 'ABC' appears in a sequence.

fn:index-of(('ABC','DEF','ABC','123'), 'ABC')

The returned value is the sequence (1,3).