<?xml version="1.0" encoding="utf-8"?>
<!--
	XSL Transformation for Cork'd Wine page.
	
	Make sure you have valid XML before, applying this stylesheet.

	http://www.ibm.com/developerworks/library/x-tiptidy.html
--> 
<xsl:stylesheet
	xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
	xmlns:html="http://www.w3.org/1999/xhtml"
	version = "1.0">
<xsl:output method = "text" />

<xsl:variable name="cr">
	<xsl:text>
</xsl:text>
</xsl:variable>

<xsl:template match = "/" >
	<xsl:apply-templates select = "//html:div[@id = 'content']" name="content" />
</xsl:template>

<xsl:template match="html:div" name="content">
	<xsl:text>Name: </xsl:text>
	<xsl:value-of select="html:h2[@id = 'wine-name']" />
	<xsl:value-of select="$cr" />
	
	<xsl:text>Color: </xsl:text>
	<xsl:value-of select="html:div[@id = 'label-bottle']/html:h4/@class" />
	<xsl:value-of select="$cr" />
	
	<xsl:text>Year: </xsl:text>
	<xsl:value-of select="html:div[@id = 'label-bottle']/html:h4" />
	<xsl:value-of select="$cr" />
	
	<xsl:apply-templates select = "html:table[contains(@class, 'wine')]" name="wine" />
</xsl:template>

<xsl:template match="html:table" name="wine">
	<xsl:text>Winery: </xsl:text>
	<xsl:apply-templates select="html:tr/html:th[contains(string(.), 'Winery')]" name="following-td" />
	<xsl:value-of select="$cr" />
	
	<xsl:text>Varietal: </xsl:text>
	<xsl:apply-templates select="html:tr/html:th[contains(string(.), 'Varietal')]" name="following-td" />
	<xsl:value-of select="$cr" />
	
	<xsl:text>Country: </xsl:text>
	<xsl:apply-templates select="html:tr/html:th[contains(string(.), 'Country')]" name="following-td" />
	<xsl:value-of select="$cr" />
	
	<xsl:text>Region: </xsl:text>
	<xsl:apply-templates select="html:tr/html:th[contains(string(.), 'Region')]" name="following-td" />
	<xsl:value-of select="$cr" />
	
	<xsl:text>Price: </xsl:text>
	<xsl:apply-templates select="html:tr/html:th[contains(string(.), 'Price')]" name="following-td" />
	<xsl:value-of select="$cr" />
</xsl:template>

<xsl:template match="html:th" name="following-td">
	<xsl:value-of select="following-sibling::html:td" />
</xsl:template>

</xsl:stylesheet>
