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:when
andxsl:otherwise
instructions can define the returned value using aselect
attribute in place of a sequence constructor. For example: -
The
<xsl:if test="$day = 'Monday'" then="1" else="0"/>xsl:if
instruction can deliver its results usingthen
andelse
attributes in place of a contained sequence constructor. For example:If the
then
attribute is present, thexsl:if
instruction 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: