<xsl:otherwise>

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.


 

Syntax

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

<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.

Attributes

The <xsl:otherwise> element has no attributes.

Examples

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