Conditional instructions
If syntax extensions are enabled, then the xsl:choose and xsl:if instructions are enhanced as follows:
-
Within
<xsl:choose> <xsl:when test="$day = 'Monday'" select="1"/> <xsl:when test="$day = 'Tuesday'" select="2"/> <xsl:when test="$day = 'Wednesday'" select="3"/> <xsl:when test="$day = 'Thursday'" select="4"/> <xsl:when test="$day = 'Friday'" select="5"/> <xsl:otherwise select="-1"/> </xsl:choose>xsl:choose, thexsl:whenandxsl:otherwiseinstructions can define the returned value using aselectattribute in place of a sequence constructor. For example: -
The
<xsl:if test="$day = 'Monday'" then="1" else="0"/>xsl:ifinstruction can deliver its results usingthenandelseattributes in place of a contained sequence constructor. For example:If the
thenattribute is present, thexsl:ifinstruction must be empty (have no children). Either attribute can be used independently; there is no requirement for both to be present.
These new forms of xsl:choose and xsl:if are particularly useful
to compute the return value of a function, replacing xsl:sequence.
The new xsl:switch instruction provides
an alternative to xsl:choose. It is best illustrated by example: