<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:r="http://nwalsh.com/xmlns/extreme2004/recipes/"
xmlns="http://www.w3.org/1999/xhtml"
version="2.0">
<xsl:template match="schema-element(r:recipe)/r:name" priority="10000">
<xsl:choose>
<xsl:when test="contains(string(parent::*), 'Habañero')">
<div class="hot">
<xsl:next-match/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:next-match/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:character-map name="html">
<xsl:output-character character=" " string=" "/>
</xsl:character-map>
<xsl:import-schema namespace="http://nwalsh.com/xmlns/extreme2004/recipes/" schema-location="recipes.xsd"/>
<xsl:output method="html" encoding="utf-8" indent="no" use-character-maps="html"/>
<xsl:strip-space elements="r:*"/>
<xsl:preserve-space elements="r:name r:source r:p"/>
<xsl:template match="r:recipeList">
<html>
<head>
<title>My Recipes</title>
<style type="text/css">
div.recipe { border-top-color: black;
border-top-width: 1px;
border-top-style: solid;
}
.bold { font-weight: bold; }
.hot { color: red; }
</style>
</head>
<body>
<h1>My Recipes</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="schema-element(r:recipe)">
<div class="recipe">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="schema-element(r:recipe)/r:name">
<h2>
<xsl:value-of select="."/>
</h2>
</xsl:template>
<xsl:template match="schema-element(r:recipe)/r:source">
<p>
<span class="bold">From: </span>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="r:ingredientList">
<h3>Ingredients</h3>
<table border="0">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="r:ingredient">
<tr>
<xsl:if test="not(r:quantity)">
<td> </td>
<td> </td>
</xsl:if>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="r:quantity">
<xsl:variable name="whole" select="floor(.)"/>
<xsl:variable name="frac" select=". - floor(.)"/>
<td align="right">
<xsl:if test="$whole > 0">
<xsl:value-of select="$whole"/>
</xsl:if>
<xsl:choose>
<xsl:when test="$frac = 0.25">¼</xsl:when>
<xsl:when test="$frac = 0.5">½</xsl:when>
<xsl:when test="$frac = 0.75">¾</xsl:when>
<xsl:when test="$frac = 0"/>
<xsl:otherwise>
<xsl:text>.</xsl:text>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</td>
<xsl:choose>
<xsl:when test="@units">
<td>
<xsl:value-of select="@units"/>
<xsl:if test=". > 1.0 and not(ends-with(@units,'s'))">s</xsl:if>
</td>
</xsl:when>
<xsl:otherwise>
<td> </td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="r:ingredient/r:name">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template match="r:list">
<ol>
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template match="r:item" priority="1000">
<li>
<xsl:apply-templates/>
</li>
</xsl:template>
<xsl:template match="r:em">
<em>
<xsl:apply-templates/>
</em>
</xsl:template>
<xsl:template match="element(*,r:Para)">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="element(*,r:Prose)">
<div>
<xsl:choose>
<xsl:when test="local-name(.) = 'preparation'">
<h3>Preparation</h3>
</xsl:when>
</xsl:choose>
<xsl:apply-templates/>
</div>
</xsl:template>
</xsl:stylesheet>