Loading TOC...

fn.indexOf

fn.indexOf(
   $seqParam as (String | Number | Boolean | null | Array | Object)[],
   $srchParam as xs.anyAtomicType,
   [$collationLiteral as String]
) as Sequence

Summary

Returns a sequence of positive integers giving the positions within the sequence $seqParam of items that are equal to $srchParam.

The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations. The collation is used when string comparison is required.

The items in the sequence $seqParam are compared with $srchParam under the rules for the eq operator. Values that cannot be compared, i.e. the eq operator is not defined for their types, are considered to be distinct. If an item compares equal, then the position of that item in the sequence $srchParam is included in the result.

If the value of $seqParam is the empty sequence, or if no item in $seqParam matches $srchParam, then the empty sequence is returned.

The first item in a sequence is at position 1, not position 0.

The result sequence is in ascending numeric order.

Parameters
$seqParam A sequence of values.
$srchParam A value to find on the list.
$collationLiteral A collation identifier.

Example

fn.indexOf(xdmp.arrayValues([10, 20, 30, 40]), 35); 
=> returns null.

fn.indexOf(xdmp.arrayValues([10, 20, 30, 30, 20, 10]), 20);
=>  returns (2, 5) as a Sequence.

fn.indexOf(xdmp.arrayValues(["a", "sport", "and", "a", "pastime"]), "a");
=>  returns (1, 4) as a Sequence.

// a is a variable whose value is the attribute @a
// of type xs:NMTOKENS whose typed value is " red green blue " 
fn.indexOf(a, "blue") returns 3.

This is because the function calling mechanism
atomizes the attribute node to produce a sequence of
three xs:NMTOKENs.

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy