Assignment 5
Solution
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:h="http://www.w3.org/1999/xhtml">
<xsl:output method="html" indent="yes"/>
<xsl:template match="catalog">
<html>
<head>
<title><xsl:value-of select="company"/> Catalog</title>
</head>
<body>
<h2 align="center"><em><xsl:value-of select="company"/> Catalog</em></h2>
<xsl:apply-templates select="department"/>
</body>
</html>
</xsl:template>
<xsl:template match="department">
<h3><xsl:value-of select="@name"/></h3>
<table border="1">
<xsl:apply-templates select="item"/>
</table>
</xsl:template>
<xsl:template match="item">
<tr>
<td width="25%">
<small><xsl:value-of select="manufacturer"/></small> <br />
<big><b><xsl:value-of select="name"/></b></big> <br />
<big><b><xsl:apply-templates select="price" /></b></big>
</td>
<td width="50%">
<xsl:choose>
<xsl:when test="description != ''">
<xsl:apply-templates select="description"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="summary"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td width="25%">
<xsl:choose>
<xsl:when test="color|color-list/color">
<table border="0" cellspacing="4">
<xsl:apply-templates select="color|color-list/color"/>
</table>
</xsl:when>
<xsl:when test="sku">
SKU: <xsl:value-of select="sku"/>
</xsl:when>
</xsl:choose>
</td>
</tr>
</xsl:template>
<xsl:template match="color">
<tr>
<td width="30" bgcolor="{@hex}">
<xsl:if test="@hex = '#ffffff'">
<xsl:attribute name="style">border: 1px solid black;</xsl:attribute>
</xsl:if>
<br />
</td>
<td><xsl:value-of select="." /></td>
</tr>
<tr>
<td colspan="2">
<small><xsl:value-of select="./@sku" /></small>
</td>
</tr>
</xsl:template>
<xsl:template match="price">
$<xsl:value-of select="@amt"/><xsl:text> </xsl:text>
<xsl:value-of select="@units"/>
</xsl:template>
<xsl:template match="h:ul|h:li|h:p|h:em|h:strong">
<xsl:element name="{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>