<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cat="http://www.iro.umontreal.ca/lapalme/wine-catalog"
xmlns="http://www.w3.org/1999/xhtml"
version="2.0">
<xsl:param name="GoogleStart">http://www.google.com/search?q=</xsl:param>
<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes"
encoding="UTF-8"/>
<xsl:key name="catalog" match="cat:wine" use="@code"/>
<xsl:template match="/">
<html>
<head>
<title>Cellar of <xsl:value-of
select="cellar-book/owner/name"/>
</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cellar-book">
<h1>Cellar of <xsl:value-of select="owner/name"/></h1>
<table border="1">
<tr>
<th>Personal address</th>
<th>Cellar address</th>
</tr>
<tr><td><xsl:for-each select="owner/*[position()>1]">
<xsl:apply-templates/><br/>
</xsl:for-each>
</td>
<td><xsl:for-each select="location/*">
<xsl:apply-templates/><br/>
</xsl:for-each>
</td>
</tr>
</table>
<p/>
<xsl:apply-templates select="cellar"/>
</xsl:template>
<xsl:template match="cellar">
<table border="1">
<tr>
<xsl:for-each
select="'Code','Name','Purchase Date','Rating','Nb bottles'">
<th><xsl:value-of select="."/></th>
</xsl:for-each>
</tr>
<xsl:apply-templates select="wine">
<xsl:sort select="@code" order="ascending"/>
</xsl:apply-templates>
<tr>
<td colspan="3">Estimated value</td>
<td align="right">
<xsl:value-of select="
sum (for $w in wine return
$w/quantity * key('catalog',$w/@code)/cat:price)"/>
</td>
<td align="right">
<xsl:value-of select="sum(wine/quantity)"/>
</td>
</tr>
</table>
<xsl:if test="count(wine/comment)>0">
<h3>Comments</h3>
<p>
<xsl:apply-templates select="wine/comment">
<xsl:sort select="../@code" order="ascending"/>
</xsl:apply-templates>
</p>
</xsl:if>
</xsl:template>
<xsl:template match="wine">
<tr>
<td><xsl:value-of select="substring(@code,2)"/></td>
<td>
<xsl:call-template name="nameAndUrl">
<xsl:with-param name="wine" select="key('catalog',@code)"/>
</xsl:call-template>
</td>
<td align="right"><xsl:value-of select="purchaseDate"/></td>
<td align="center">
<xsl:value-of select="substring('*****',1,
if (rating/@stars) then rating/@stars else 0)"/></td>
<td align="right"><xsl:value-of select="quantity"/></td>
</tr>
</xsl:template>
<xsl:template name="nameAndUrl">
<xsl:param name="wine"/>
<xsl:variable name="name" select="encode-for-uri($wine/@name)"/>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$GoogleStart"/>
<xsl:value-of select="$name"/>
</xsl:attribute>
<xsl:value-of select="$wine/@name"/>
</a>
<br/>
<i>
<a href="{$GoogleStart}{$name}">
<xsl:value-of select="$wine/@name"/>
</a>
</i>
</xsl:template>
<xsl:template match="comment"><xsl:text>
</xsl:text>
<xsl:value-of select="../@code"/>
<xsl:text> : </xsl:text>
<xsl:apply-templates/><br/>
</xsl:template>
<xsl:template match="cat:bold">
<b><xsl:apply-templates/></b>
</xsl:template>
</xsl:stylesheet>