<?xml version="1.0" encoding="UTF-8"?>
<!--
XSL Style-Sheet for Cellar Tasting Notes
(c) 2008 Jacob Gifford Head
http://www.jacob-head.com/

This work is licenced under the "Creative Commons 
Attribution-Non-Commercial-Share Alike 2.0 
UK: England & Wales Licence"
For full details see:
http://creativecommons.org/licenses/by-nc-sa/2.0/uk/

Comments, suggestions, problems and additions are always welcome.
scripts ~~ at ~~ jacob-head ~~ dot ~~ com
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" lang="text" omit-xml-declaration = "yes" />
<xsl:param name="break-at" select="'70'" />
<xsl:template match="/">
*********Cellar Details and Tasting Notes*********
<xsl:for-each select="cellar/wine">
***<xsl:value-of select="text()" />***
 _______________________________________________________________________
|Year	|Type		|Number	|Rating	|Producer 			|
|_______|_______________|_______|_______|_______________________________|
<xsl:for-each select="bottle">
<xsl:sort select="*[name()=type]" />
<xsl:choose>
<xsl:when test="year">|<xsl:value-of select="year" />&#9;|</xsl:when>
<xsl:otherwise>|N/V&#9;|</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="age"><xsl:value-of select="age" /> Y/O <xsl:value-of select="type" />&#9;|</xsl:when>
<xsl:when test="type[string-length(text())&gt;6]"><xsl:value-of select="type" />&#9;|</xsl:when>
<xsl:otherwise><xsl:value-of select="type" />&#9;&#9;|</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="number"><xsl:value-of select="number" />&#9;|</xsl:when>
<xsl:otherwise>1&#9;|</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="rating" />&#9;|<xsl:value-of select="shipper" /> <xsl:if test="name">'s 
|	|		|	|	|<xsl:value-of select="name" />
</xsl:if>
<xsl:if test="quinta">'s <xsl:value-of select="quinta" /></xsl:if>
<xsl:choose>
<xsl:when test="notes">
|_______|_______________|_______|_______|_______________________________|
|Notes:									| 
|<xsl:call-template name="fold">
<xsl:with-param name="text" select="notes" />

</xsl:call-template>
|_______________________________________________________________________|
</xsl:when><xsl:otherwise>
|_______|_______________|_______|_______|_______________________________|
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template name="fold">
<xsl:param name="text" />
<xsl:choose>
<xsl:when test="string-length($text) &lt;= $break-at">
<xsl:value-of select="$text" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($text, 1, $break-at)" />	|
|<xsl:call-template name="fold"> <xsl:with-param name="text" select="substring($text, $break-at + 1)" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
