XSLT Function - <xsl:otherwise>

The XSLT <xsl:otherwise> element provides a default value/evaluation within the scope an <xsl:choose> conditional evaluation.

<xsl:otherwise> is only evaluated within an <xsl:choose> when all preceding <xsl:when> test conditions failed to evaluated to true.

The <xsl:otherwise> element cannot be used on its own; it must always be used together with corresponding <xsl:choose> and <xsl:when>  elements.

When used inside an <xsl:choose> then there can only be one <xsl:otherwise> element.



<xsl:when test="expression_1">
<!-- evaluated when expression_1 is true. -->
<xsl:when test="expression_2">
<!-- evaluated when expression_2 is true. -->
<!-- ... -->
<xsl:when test="expression_n">
<!-- evaluated when expression_n is true. -->
<!-- evaluated when none of the preceding expressions are true.-->

<xsl:choose> contains one or more nested <xsl:when> elements and one optional <xsl:otherwise> element. Only the contents one <xsl:when> element is evaluated when its corresponding expression returns true; otherwise the <xsl:otherwise> content is evaluated if it is defined.


The <xsl:otherwise> element has no attributes.


The <xsl:otherwise> element must be used inside a <xsl:choose> element. Refer to the examples presented under <xsl:choose> for a better overview on how to use this function in an XSLT transform.

Posted in XSLT and tagged .

Leave a Reply