Skip to content

XQuery index-of Function

How to use the XQuery index-of function to find the position of a specific item within a sequence and return its integer index.

XQuery index-of Function

The index-of function is used to track items in the given sequence. It returns integers to indicate the availability of items in a given sequence.

Syntax

index-of($seq as anyAtomicType()*, $target as anyAtomicType())

Input Parameters

  • $seq is the provided sequence. A sequence can contain 0 or more items.
  • $target is the item whose index is to be returned.

Example

XQuery Expressionxquery
let $items := (1,2,3,4,5,6)
let $indexOf := index-of($items,4)
return
   <result>   
      <indexof>{$indexOf}</indexof>
   </result>
Outputxml
<result>   
   return <indexof>4</indexof>
</result>
Navigation