Choose Construct
If you want to do successive checks like "if-else" or "if-else if – else if", then you can use the Choose construct.
The format is:
<choose>
<when>
...
</when>
<when>
...
</when>
<otherwise>
...
</otherwise>
</choose>
If first <when> condition matches, then the instructions within that section are executed. Else, the second <when> condition is attempted. If none of the when condition matches, then the instructions within the <otherwise> section are executed. The <otherwise> section is optional.
The following concrete example shows a full choose statement.
<choose>
<when test="$_severity IN '6, 7'">
<setEventAttribute attr="eventSeverity">1</setEventAttribute>
</when>
<when test="$_severity = '1'">
<setEventAttribute attr="eventSeverity">10</setEventAttribute>
</when>
<when test="$_severity = '2'">
<setEventAttribute attr="eventSeverity">8</setEventAttribute>
</when>
<when test="$_severity IN '3, 4'">
<setEventAttribute attr="eventSeverity">5</setEventAttribute>
</when>
<when test="$_severity = '5'">
<setEventAttribute attr="eventSeverity">2</setEventAttribute>
</when>
<otherwise>
<setEventAttribute attr="eventSeverity">1</setEventAttribute>
</otherwise>
</choose>
Results of execution:
-
If
severityis 2 theneventSeverityis 8. -
If
severityis 11 theneventSeverityis 1.