fn:position

Return position of context item in current sequence.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

fn:position => unsignedInt?

Description

This context function returns the position of the context item within the sequence of items that is currently being processed. The function returns the empty sequence if the context is the empty sequence.

Example

  • Retrieve the first even natural numbers:

    let $numbers := ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10" )
    return $numbers[position() mod 2 = 0]

    The query returns all those sequence items whose position modulo 2 equals 0, i.e., which is an even number.