Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
Provides multiple conditional testing in conjunction with the <xsl:choose> and <xsl:otherwise> elements.
Syntax
<xsl:when test = boolean expression> </xsl:when> |
Attributes
- test
-
[required] The condition in the source data to test. If the expression in this attribute evaluates to True when cast to a Boolean, the contents of <xsl:when> are placed in the output. Node-sets are cast to a Boolean True if they contain at least one node.
Element Information
Number of occurrences |
Unlimited |
Parent elements |
|
Child elements |
xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:value-of, xsl:variable, output elements |
Remarks
Describes one of the alternatives to be chosen by the < xsl:choose> element. The default alternative is described by the < xsl:otherwise> element.
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.
Copy Code | |
---|---|
<xsl:template match="order"> <xsl:choose> <xsl:when test="total < 10"> <HR STYLE="color:red"/> </xsl:when> <xsl:when test="total < 20"> <HR STYLE="color:pink"/> </xsl:when> <xsl:otherwise> <BR/> </xsl:otherwise> </xsl:choose> <xsl:apply-templates /> </xsl:template> |