<for>
This looping statement processes any children statements in a repeated loop for the specified count. The count may be static or may use expressions to define a dynamic limit. The increment is always one.
You can use most EMML statements within <for>. You can also use <break> within this statement to forceably stop loop processing.
| Can Contain | ( Statements Group | ( Variables Group ) | ( ( macro:custom-macro-name | any element in a non-EMML namespace )* ) | ( break ) | ( variables ) )+ |
| Allowed In | mashup, else, elseif, for, foreach, if, macro, operation, sequence, while, |
Attributes
| Name | Required | Description |
|---|---|---|
| variable | yes | The name for the counter variable for this looping statement. The scope for this variable is limited to the <for> loop. |
| startcountervalue | yes | The number or expression that defines the number to use as the counter for the first loop. The increment is always one. |
| finalcountervalue | yes | The number or expression that defines the number of the last loop to execute. Expressions must evaluate to an integer value. |
<for> Example
You must define the counter variable and the beginning and final values for the counter. The counter limits can be integers or XPath 2.0 expressions that evaluate to integers. The loop increment is always one.
Note: the counter variable in <for> is implicitly declared and has a local scope of the <for> command only.
As with other programming languages, you can use the counter variable name in expressions used in statements within the body of <for>.
One common use of <for> loops is to repeatedly append content to a variable, as shown in the following example:
<variables>
<variable name="reviewers" type="document"/>
<variable name="compositeResult" type="document"/>
</variables>
...
<for variable="$i" startcountervalue="1"
finalcountervalue="count($reviewers//reviewer)">
<display message="reviewer is " variable="$reviewers//reviewer[$i]/name"/>
<appendresult outputvariable="$compositeResult">
<res:ratingBy>
<res:name>{string($reviewers//reviewer[$i]/name)}</name>
<res:rating>{string($reviewers//reviewer[$i]/rating)}</rating>
</res:ratingBy>
</appendResult>
</for>
Enterprise Mashup Markup Language (EMML) Documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
