Name

<xsl:otherwise>

Defines the else or default case in an <xsl:choose> element. This element always appears inside an <xsl:choose> element, and it must always appear last.

Category

Subinstruction (<xsl:otherwise> always appears as part of an <xsl:choose> element).

Required Attributes

None.

Optional Attributes

None.

Content

A template.

Appears in

The <xsl:choose> element.

Defined in

[1.0] XSLT section 9.2, “Conditional Processing with xsl:choose.”

[2.0] XSLT section 8.2, “Conditional Processing with xsl:choose.”

Example

Here’s an example that uses <xsl:choose> to select the background and foreground colors for the rows of an HTML table. We cycle among four different values, using <xsl:otherwise> to determine the default value of the style attribute in the generated HTML document. Here’s the XML document we’ll use:

<?xml version="1.0"?>
<!-- albums.xml -->
<list xml:lang="en">
  <title>Albums I've bought recently:</title>
  <listitem>The Sacred Art of Dub</listitem>
  <listitem>Only the Poor Man Feel It</listitem>
  <listitem>Excitable Boy</listitem>
  <listitem xml:lang="sw">Aki Special</listitem>
  <listitem xml:lang="en_GB">Combat Rock</listitem>
  <listitem xml:lang="zu">Talking Timbuktu</listitem>
  <listitem xml:lang="jz">The Birth of the Cool</listitem>
</list>

And here’s our stylesheet:

<?xml version="1.0"?>
<!-- otherwise.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> <title> <xsl:value-of select="list/title"/> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.