The index() Function

Release 2.0 - ...

Syntax

  CopyCode image Copy Code
number index(string)

Description

Function index() takes a string argument that is the IDREF of a repeat and returns the current 1-based position of the repeat index for the identified repeat.
If the specified argument does not identify a repeat, the function returns NaN.

Notice that the index() usually returns 1, unless it's manipulated via XForms Action setindex or if one or more nodes have been added to the repeat collection by an insert action.

Example

XML CopyCode image Copy Code
<xforms:model xmlns:ex="http://example.org">
   <xforms:instance>
      <ex:root>
         <ex:value>2</ex:value>
         <ex:value>6</ex:value>
      </ex:root>
   </xforms:instance>
</xforms:model> 
 ...
<xforms:repeat nodeset="ex:value" id="myrepeat" startindex="2">
   <xforms:group>
      <xforms:output value="concat(.,' (index: ',index('myrepeat'),')')" />
   </xforms:group>
</xforms:repeat>

The above example will return "6 (index: 2)".

Specification

Link to the XForms specification: the index() function.