Easy Tutorial
❮ El Comment El Template ❯

XSLT <xsl:when> Element



Definition and Usage

The <xsl:when> element is used to specify the associated action for the <xsl:choose> element. The <xsl:when> element evaluates an expression, and if it returns true, the specified action is executed.

Note: The <xsl:when> element is used in conjunction with the <xsl:choose> and <xsl:otherwise> elements to express multiple conditional tests.


Syntax

Attributes

Attribute Value Description
test boolean-expression Required. Specifies the boolean expression to test.

Example 1

The following code adds a pink background color to the artist column if the price of the cd is higher than 10.

View XML File, View XSL File, View Result.

Example 2

A variable named "color" is declared. Its value is assigned to the color attribute of the current element. If the current element does not have a color attribute, the value of "color" will be "green":


❮ El Comment El Template ❯