choose
Define a group of mutually exclusive choices. The contents of this tag are restricted to 'when' and 'otherwise' tags only.
During execution of this tag, each 'when' and 'otherwise' tag is evaluated in sequence. If one of these tags evaluates to 'true', then any subsequent tags are ignored. A 'when' tag evaluates to 'true' if its 'test' attribute's XPath expression evaluates to 'true'. An 'otherwise' tag evaluates to 'true' if no preceeding 'when' (or 'otherwise') tag has evaluated to true.
Tag Summary |
required |
<c:choose>
content to be written
</c:choose>
|
full tag |
<c:choose select="value">
content to be written
</c:choose>
|
Optional Attributes |
select |
Optional test expression. When specified, each 'when' tag 'test' expression is tested for equality against this value. When not specified, this is the equivalent of the XPath expression 'true()'. |
Example |
|
<%-- evaluate one of a number alternatives --%>
<c:choose>
<c:when test="$var/@value = 1">
handle case 1
</c:when>
<c:when test="$var/@value >= 2">
handle case 2
</c:when>
<c:otherwise>
handle other cases
</c:otherwise>
</c:choose>
<%-- evaluate an expression against constances --%>
<c:choose select="$var/@num">
<c:when test=" 'one' ">
handle case 'one'
</c:when>
<c:when test=" 'two' ">
handle case 'two'
</c:when>
<c:otherwise>
handle other cases
</c:otherwise>
</c:choose>
|