YouTip LogoYouTip

El Otherwise

XSLT Element

-- Learning is not only technology, but also dreams!

XSLT Tutorial

XSLT Elements

XSLT Functions

XSLT Transformation Tools

XSLT Examples

XSLT Functions

Explore More

XSLT Element

Complete XSLT Element Reference Manual

Definition and Usage

The element specifies the default behavior of the element. This behavior occurs when none of the conditions apply.

Syntax

<xsl:otherwise>
    <!-- Content:template -->
</xsl:otherwise>

Attributes

None

Example 1

The following code will add a pink background color to the artist column if the price of the cd is higher than 10, otherwise it will just output the name of the artist:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price>'10'">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

View XML file, View XSL file, View Result.

Example 2

Declare a variable named "color". Assign its value 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":

<xsl:variable name="color">
<xsl:choose>
<xsl:when test="@color">
<xsl:value-of select="@color"/>
</xsl:when>
<xsl:otherwise>green</xsl:otherwise>
</xsl:choose>
</xsl:variable>

Complete XSLT Element Reference Manual

XSLT Examples

XSLT Functions

ByteArk Coding Plan

Supports mainstream large models such as Doubao, GLM, DeepSeek, Kimi, MiniMax, etc., directly supplied by the official for stable and reliable service.

Β₯9.9 / month

Xunfei Starry Coding Plan

Includes free model call quota, one-stop experience and deployment platform with DeepSeek, GLM, Kimi, MiniMax.

Β₯3.9 / month

Category Navigation

Advertisement

XSLT Tutorial

XSLT Tutorial

XSL Language

XSLT Introduction

XSLT Browser

XSLT Transformation

XSLT

Online Examples

Character Set & Tools

Latest Updates

Site Information

Follow WeChat

My Favorites

Browsing History

No Records

← El OutputEl Number β†’