Description
The fn:index-of function returns the position(s) of an atomic value within a sequence. The $seqParam argument is the sequence to be searched, while $srchParam is the value to search for. This function returns a sequence of integers representing the position(s) of the value within the sequence, in order, starting with 1 (not 0).
The $seqParam sequence must contain all atomic values, or nodes that have atomic typed values. The items in the sequence are compared to the search value by their typed value, not node identity. Untyped values are treated like strings.
This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book. Arguments and Return TypeName | Type | Description |
$seqParam |
xs:anyAtomicType* |
the sequence of values |
$srchParam |
xs:anyAtomicType |
the value to find the index of |
$collation |
xs:string |
the collation to use for comparing strings |
return value |
xs:integer* |
ExamplesXQuery Example | Results |
---|
index-of( ('a', 'b', 'c'), 'a') |
1 |
index-of( ('a', 'b', 'c'), 'd') |
() |
index-of( (4, 5, 6, 4), 4) |
(1, 4) |
index-of( (4, 5, 6, 4), 04.0) |
(1, 4) |
index-of( ('a', 5, 6), 'a') |
1 |
index-of( (), 'a') |
() |
index-of( (<a>1</a>, <b>1</b>), <c>1</c> ) |
(1, 2) |
See AlsoHistory |
Recommended Reading:
|