home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="utf-8"?>
- <!-- ===========================================================
- Category: XSLT
- Sub-category: xsl:otherwise
- Author: David Silverlight
- HeadGeek@xmlpitstop.com
- Created: 2001-05-16
- Description:-
- This stylesheet demonstrates the use of xsl:otherwise to
- display a value if none of the tests in an xsl:choose equates
- to true. In this example, if none of the language
- translation tests equates to true, the xsl:otherwise is
- performed to display "English" as the spoken language.
- =============================================================== -->
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
- <xsl:output method="html" />
-
- <xsl:template match="/">
- <html>
- <head>
- <title>Stylesheet Example</title>
- <style type="text/css"><![CDATA[
- H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
- H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
- .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
- TD {COLOR: darkblue; FONT-FAMILY: Arial}
- TR { background-color: beige; }
- BODY { background-color: beige; }
- ]]></style>
- </head>
- <body>
- <xsl:apply-templates />
- </body>
- </html>
- </xsl:template>
-
- <!-- Template for "employees" elements -->
- <xsl:template match="employees">
- <h1>Employee listing showing programming and spoken languages</h1>
- <table border="1">
- <tr>
- <th>Department</th>
- <th>Name</th>
- <th>Hourly Rate</th>
- <th>Programming Language</th>
- <th>Spoken Language</th>
- </tr>
- <xsl:for-each select="employee">
- <tr>
- <td>
- <xsl:value-of select="department" />
- </td>
- <td>
- <xsl:value-of select="employeename" />
- </td>
- <td>
- <xsl:value-of select="hourlyrate" />
- </td>
- <td>
- <xsl:value-of select="primarylanguage" />
- </td>
- <td>
- <xsl:choose>
- <xsl:when test="nativelanguage = 'EN'">
- <xsl:value-of select="'English'" />
- </xsl:when>
- <xsl:when test="nativelanguage = 'FR'">
- <xsl:value-of select="'French'" />
- </xsl:when>
- <xsl:when test="nativelanguage = 'SP'">
- <xsl:value-of select="'Spanish'" />
- </xsl:when>
- <xsl:when test="nativelanguage = 'TH'">
- <xsl:value-of select="'Thai'" />
- </xsl:when>
- <xsl:when test="nativelanguage = 'GR'">
- <xsl:value-of select="'German'" />
- </xsl:when>
- <xsl:otherwise>
- <!-- The Otherwise clause will be processed when none of the tests
- equates to a true value. In this example, since the author
- of the sample lives in the united states, we will default
- the language to English if it does not match any of the defined
- languages :) -->
- <xsl:value-of select="'English'" />
- </xsl:otherwise>
- </xsl:choose>
- </td>
- </tr>
- </xsl:for-each>
- </table>
- </xsl:template>
- </xsl:stylesheet>