Iteration with the ForEach Element

In some places, it is useful to be able to perform the same operation repeatedly to process each one of a set of values. The specification file supports a simple ForEach iterator that binds a temporary property to each value in the supplied set in turn. The ForEach loop can be set up to iterate in one of the following ways:

Format

<ForEach var="field_name" from="integer_exp" to="integer_exp" step="integer_exp" 
inFields="fields" inFieldValues="field_name" inProperty="property_name" >
   -- data model operation --
</ForEach>

where:

var (required) specifies the field containing the values to which the iteration will apply.

from and to specify integers (or expressions that evaluate to integers) that denote the lower and upper limits of the iteration, with the optional attribute step indicating an integer step size.

inFields, inFieldValues and inProperty are alternatives to the from/to/step format:

The data model operation that can be specified within a ForEach element is any of the AddField, ChangeField or RemoveField elements. See the topic Data Model Operations for more information. ForEach elements can also be nested.

Examples

The following performs an operation ten times:

<ForEach var="val" from="1" to="10">
 ...
</ForEach>

The following performs an operation the number of times specified by an integer property:

<ForEach var="val" from="1" to="${history_count}">
 ...
</ForEach>

In the next example, processing iterates through the values in the output fields for the node:

<ForEach var="field" inFields="outputs">
 ...
</ForEach>

The following example iterates through the values in the metadata for the field identified by ${field}:

<ForEach var="fieldValue" inFieldValues="${field}">
 ...
</ForEach>

The next example iterates through the values in a list property:

<ForEach var="val" inProperty="my_list_property">
 ...
</ForEach>

The following iterates through the key values in a keyed property:

<ForEach var="key" inProperty="my_keyed_property">
 ...
</ForEach>