Provides multiple conditional testing in conjunction with the xsl:choose and xsl:when elements.
Syntax
<xsl:otherwise >
</xsl:otherwise>
Element Information
Number of occurrences | Unlimited |
Parent elements | xsl:choose |
Child elements | xsl:apply-templates, xsl:attribute, xsl:choose, xsl:comment, xsl:copy, xsl:element, xsl:eval, xsl:for-each, xsl:if, xsl:pi, xsl:value-of, output elements |
Requires closing tag | Yes. XSL is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of well-formed. |
Remarks
Provides a default condition for xsl:choose. Other alternatives are indicated by xsl:when elements.
For simple conditional testing, use the xsl:if element.
Example
This example shows a template for "order" elements, and inserts an HR or BR before the order's contents based on the order's "total" element value. If the total is less than 10, a red HR will be generated; if the total is less than 20, a pink HR will be generated; otherwise a BR element will be created.
<xsl:template match="order">
<xsl:choose>
<xsl:when test="total[. $lt$ 10]">
<HR STYLE="color:red"/>
</xsl:when>
<xsl:when test="total[. $lt$ 20]">
<HR STYLE="color:pink"/>
</xsl:when>
<xsl:otherwise>
<BR/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates />
</xsl:template>
See Also