<if>
This conditional statement follows the well-known if-elseif-else control pattern to processes specific children statements based on one or more conditions. Both <elseif> and <else> are optional.
You can use most EMML statements within <if>, <elseif> or <else>. You can also use <break> within these statements if they are descendants of a looping statement to forceably stop the ancestor loop processing.
You define the conditions that must be matched for each section of this statement to be processed as XPath 2.0 expressions. For examples, see <if> Basics, Adding <elseif> or <else> or Breaking.
| Can Contain | ( ( Statements Group | ( Variables Group ) | ( ( macro:custom-macro-name | any element in a non-EMML namespace )* ) | ( break ) | ( variables ) )+ , elseif* , else? ) |
| Allowed In | mashup, else, elseif, for, foreach, if, macro, operation, sequence, while, |
Attributes
| Name | Required | Description |
|---|---|---|
| condition | yes | An expression for the initial condition to test for the <if> statement. If this condition is matched, the statements that are direct children of <if> (not including <elseif> or <else>) are processed. |
<elseif>
An optional, alternate condition with a set of statements to process if this condition is matched.
| Can Contain | ( Statements Group | ( Variables Group ) | ( ( macro:custom-macro-name | any element in a non-EMML namespace )* ) | ( break ) | ( variables ) )+ |
Attributes
| Name | Required | Description |
|---|---|---|
| condition | yes | An expression for the condition to test for the <elseif> statement. If this condition is matched, the statements that are direct children of <elseif> are processed and any subsequent <elseif> statements or the <else> statement is skipped. |
<else>
A optional statement with a default set of children statements to process if no conditions are matched.
| Can Contain | ( Statements Group | ( Variables Group ) | ( ( macro:custom-macro-name | any element in a non-EMML namespace )* ) | ( variables ) )+ |
<if> Examples
<if> Basics
At a minimum, you define <if> with a condition and add statements inside <if>, such as the following example:
<variables>
<variable name="destination" type="document"/>
<variable name="local" type="string" default="US"/>
</variables>
...
<if condition="$destination//country != $local">
<directinvoke endpoint="http://weather.yahooapis.com/forecastrss?p=94102"
method="get" outputvariable="$sfWeather"/>
</if>
Adding <elseif> or <else>
To include additional conditions, add <elseif> or <else> elements as children of <if>. You can have any number of <elseif> statements. For example:
<if condition="$sortingType/sortBy = 'date'">
<sort intputvariable="$tasks" sortexpr="/task" sortkeys="dueDate"
outputvariable="$tasks"/>
<elseif condition="$sortingType/sortBy = ’name’">
<sort intputvariable="$tasks" sortexpr="/task" sortkeys="description"
outputvariable="$tasks"/>
</elseif>
<else>
<sort intputvariable="$tasks" sortexpr="/task" sortkeys="priority"
outputvariable="$tasks"/>
</else>
</if>
Breaking
When <if> is inside a looping statement (<for>, <foreach> or <while>), you can also use <break/> inside <if> or <elseif> to stop all subsequent processing for this loop and any further looping.
For examples using <break/>, see the <break> statement.
Enterprise Mashup Markup Language (EMML) Documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
