XSLT xsl:when Element
Complete XSLT Element Reference Manual
Definition and Usage
xsl:when The element is used to specify actions for the xsl:choose element. xsl:when The element evaluates an expression, and if it returns true, the specified action is performed.
Note:xsl:when element is used together with xsl:choose element and xsl:otherwise The elements are used together to express multiple conditional tests.
Syntax
test="boolean-expression">
property
| property | Value | Description |
|---|---|---|
| test | boolean-expression | Required. Specifies the Boolean expression to test. |
Example 1
The code below adds a pink background color to the artist column when the price of a cd is greater than 10.
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">My CD Collection
Title
Artist
View the XML file、 View the XSL file、 View the result。
Example 2
Declares a variable named "color". Its value is assigned to the color attribute of the current element. If the current element has no color attribute, the value of "color" will be "green":
xsl:otherwisegreen
Complete XSLT Element Reference Manual