XSL reference documentation generated from the W3C Recommendation 16 November 1999
xsl:choose
<choose>
Model: (when+, otherwise?)
</choose>
<when>
test = boolean-expression
Model: template
</when>
<otherwise>
Model: template
</otherwise>
The xsl:choose element selects one among a number of
possible alternatives. It consists of a sequence of
xsl:when elements followed by an optional
xsl:otherwise element. Each xsl:when
element has a single attribute, test, which specifies an
xsl:when and xsl:otherwise elements is a
template. When an xsl:choose element is processed, each
of the xsl:when elements is tested in turn, by evaluating
the expression and converting the resulting object to a boolean as if
by a call to the xsl:when element whose
test is true is instantiated. If no xsl:when is true,
the content of the xsl:otherwise element is
instantiated. If no xsl:when element is true, and no
xsl:otherwise element is present, nothing is created.
The following example enumerates items in an ordered list using arabic numerals, letters, or roman numerals depending on the depth to which the ordered lists are nested.
<xsl:template match="orderedlist/listitem">
<fo:list-item indent-start='2pi'>
<fo:list-item-label>
<xsl:variable name="level"
select="count(ancestor::orderedlist) mod 3"/>
<xsl:choose>
<xsl:when test='$level=1'>
<xsl:number format="i"/>
</xsl:when>
<xsl:when test='$level=2'>
<xsl:number format="a"/>
</xsl:when>
<xsl:otherwise>
<xsl:number format="1"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>. </xsl:text>
</fo:list-item-label>
<fo:list-item-body>
<xsl:apply-templates/>
</fo:list-item-body>
</fo:list-item>
</xsl:template>