The xsl:choose, xsl:when, and xsl:otherwise Elements

The previous example showed you how to use multiple <xsl:if> elements in situations where there are alternatives. Although this works, it's ungainly when there are several possible values. In that case, it's better to use a combination of the <xsl:choose>, <xsl:when>, and <xsl:otherwise> elements. The following two sections illustrate how these elements are used.

An xsl:choose and xsl:when Example

Reopen listing14-4.xml and change

<Book>
<Title>Teach Yourself Uses of Silicon in 24 Hours</Title>
<Author>
<Name>Missy Fixit</Name>

to

<Book BestSeller="impossible">
<Title>Teach Yourself Uses of Silicon in 24 Hours</Title>
<Author>
<Name>Missy Fixit</Name>

Add the two additional records that ...

Get Sams Teach Yourself XML in 24 Hours 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.