﻿<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:hav="http://www.HopAndVineHull.co.uk/Drinks" 
    exclude-result-prefixes="hav">

  <xsl:template match="/">
    <xsl:apply-templates select="hav:Drinks"/>
  </xsl:template>

  <xsl:template match="hav:Drinks">
    <xsl:apply-templates select="hav:Section"/>
    <br/>
    <div class="drinksFooter">
      <xsl:text>Prices correct at </xsl:text>
      <xsl:value-of select="@ValidFrom"/>
      <xsl:text>. E&amp;OE.</xsl:text>
    </div>
  </xsl:template>

  <xsl:template match="hav:Section">
    
    <div class="drinksSection">
      <xsl:if test="@Icon">
        <span class="drinksIcon">
          <img alt="icon" src="{@Icon}"/>
        </span>
      </xsl:if>
      <a id="{translate(@Name, ' ', '_')}" name="{translate(@Name, ' ', '_')}">
        <xsl:value-of select="@Name"/>
        <xsl:text>&#160;</xsl:text>
      </a>
    </div>
    
    <table cellspacing="0" cellpadding="0" class="entry">
      <xsl:apply-templates/>
    </table>
    
  </xsl:template>

  <xsl:template match="hav:Section[parent::hav:Section]">
    <xsl:if test="position() &gt; 1">
      <tr>
        <td colspan="4">&#160;</td>
      </tr>
    </xsl:if>
    <xsl:apply-templates/>
  </xsl:template>

  <!-- D R A U G H T -->
  <xsl:template match="hav:Draught">
    
    <xsl:if test="position() = 1">
      <tr>
        <th class="entryTitle">
          <xsl:value-of select="parent::hav:Section/@Name | parent::hav:Section/@Heading"/>&#160;
        </th>
        <th class="entryColumn">&#160;</th>
        <xsl:choose>
          <xsl:when test="@Half">
            <th class="entryColumn">
              <xsl:text>&#160;</xsl:text>
              <xsl:if test="@Pint">Pint</xsl:if>
            </th>
            <th class="entryColumn">
              <xsl:text>&#160;</xsl:text>
              <xsl:if test="@Half">Half</xsl:if>
            </th>
          </xsl:when>
          <xsl:otherwise>
            <th class="entryColumn">
              <xsl:if test="@ABV">ABV</xsl:if>
              <xsl:text>&#160;</xsl:text>
            </th>
            <xsl:choose>
              <xsl:when test="@Size">
                <th class="entryColumn">
                  <xsl:value-of select="@Size"/>
                </th>
              </xsl:when>
              <xsl:otherwise>
                <th class="entryColumn">Price</th>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
      </tr>
    </xsl:if>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="position() mod 2 = 1">
          <xsl:text>oddRow</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>evenRow</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    
    <tr class="{$class}">
      <td class="alignLeft">
        <xsl:if test="@Maker">
          <xsl:value-of select="@Maker"/>
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="@Name"/>
        <xsl:if test="@New and @New = 'true'">
          <b> * NEW *</b>
        </xsl:if>
      </td>
      <xsl:choose>
        <xsl:when test="@Price">
          <td>&#160;</td>
          <td>
            <xsl:if test="@ABV">
              <xsl:value-of select="@ABV"/>
              <xsl:text>%</xsl:text>
            </xsl:if>
          </td>
          <td>
            <xsl:text>£</xsl:text>
            <xsl:value-of select="@Price"/>
          </td>
        </xsl:when>
        <xsl:otherwise>
          <td>&#160;</td>
          <td>
            <xsl:text>£</xsl:text>
            <xsl:value-of select="@Pint"/>
          </td>
          <td>
            <xsl:text>£</xsl:text>
            <xsl:value-of select="@Half"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="@Size"/>
          </td>
        </xsl:otherwise>
      </xsl:choose>
    </tr>
  </xsl:template>

  <!-- B O T T L E -->
  <xsl:template match="hav:Bottle">
    
    <xsl:if test="position() = 1">
      <tr>
        <th class="entryTitle">
          <xsl:value-of select="parent::hav:Section/@Name | parent::hav:Section/@Heading"/>&#160;
        </th>
        <xsl:choose>
          <xsl:when test="@ABV">
            <th class="entryColumn">Size</th>
            <th class="entryColumn">ABV</th>
          </xsl:when>
          <xsl:otherwise>
            <th class="entryColumn">&#160;</th>
            <th class="entryColumn">Size</th>
          </xsl:otherwise>
        </xsl:choose>
        <th class="entryColumn">Price</th>
      </tr>
    </xsl:if>

    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="position() mod 2 = 1">
          <xsl:text>oddRow</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>evenRow</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <tr class="{$class}">
      <td class="alignLeft">
        <xsl:if test="@Maker">
          <xsl:value-of select="@Maker"/>
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="ancestor::hav:Section/@Name = 'Bottled Belgian Beers'">
            <b><xsl:value-of select="@Name"/></b>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@Name"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="@New and @New = 'true'">
          <b> * NEW *</b>
        </xsl:if>
      </td>
      <xsl:choose>
        <xsl:when test="@ABV">
          <td>
            <xsl:value-of select="@Size"/>
          </td>
          <td>
            <xsl:value-of select="@ABV"/>
            <xsl:text>%</xsl:text>
          </td>
        </xsl:when>
        <xsl:otherwise>
          <td>&#160;</td>
          <td>
            <xsl:value-of select="@Size"/>
          </td>
        </xsl:otherwise>
      </xsl:choose>
      <td>
        <xsl:text>£</xsl:text>
        <xsl:value-of select="@Price"/>
      </td>
    </tr>
  </xsl:template>

  <!-- S P I R I T -->
  <xsl:template match="hav:Spirit">
    
    <xsl:if test="position() = 1">
      <tr>
        <th class="entryTitle">
          <xsl:value-of select="parent::hav:Section/@Name | parent::hav:Section/@Heading"/>&#160;
        </th>
        <th class="entryColumn">&#160;</th>
        <xsl:choose>
          <xsl:when test="@Measure='25ml'">
            <th class="entryColumn">25ml</th>
            <th class="entryColumn">50ml</th>
          </xsl:when>
          <xsl:otherwise>
            <th class="entryColumn">35ml</th>
            <th class="entryColumn">70ml</th>
          </xsl:otherwise>
        </xsl:choose>
      </tr>
    </xsl:if>

    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="position() mod 2 = 1">
          <xsl:text>oddRow</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>evenRow</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <tr class="{$class}">
      <td class="alignLeft">
        <xsl:if test="@Maker">
          <xsl:value-of select="@Maker"/>
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="@Name"/>
        <xsl:if test="@New and @New = 'true'">
          <b> * NEW *</b>
        </xsl:if>
      </td>
      <td>&#160;</td>
      <td>
        <xsl:choose>
          <xsl:when test="@Single">
            <xsl:text>£</xsl:text>
            <xsl:value-of select="@Single"/>
          </xsl:when>
          <xsl:otherwise>-&#160;&#160;&#160;</xsl:otherwise>
        </xsl:choose>
      </td>
      <td>
        <xsl:choose>
          <xsl:when test="@Double">
            <xsl:text>£</xsl:text>
            <xsl:value-of select="@Double"/>
          </xsl:when>
          <xsl:otherwise>-&#160;&#160;&#160;</xsl:otherwise>
        </xsl:choose>
      </td>
    </tr>
  </xsl:template>

  <!-- W I N E -->
  <xsl:template match="hav:Wine">
    
    <xsl:if test="position() = 1">
      <tr>
        <th class="entryTitle">
          <xsl:value-of select="parent::hav:Section/@Name | parent::hav:Section/@Heading"/>&#160;
        </th>
        <th class="entryColumn">175ml</th>
        <th class="entryColumn">250ml</th>
        <xsl:choose>
          <xsl:when test="@Carafe">
            <th class="entryColumn">Carafe</th>
          </xsl:when>
          <xsl:otherwise>
            <th class="entryColumn">Bottle</th>
          </xsl:otherwise>
        </xsl:choose>
      </tr>
    </xsl:if>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="position() mod 2 = 1">
          <xsl:text>oddRow</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>evenRow</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <tr class="{$class}">
      <td class="alignLeft">
        <xsl:if test="@Maker">
          <xsl:value-of select="@Maker"/>
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="@Name"/>
        <xsl:if test="@Country">
          <xsl:text> (</xsl:text>
          <xsl:value-of select="@Country"/>
          <xsl:text>) </xsl:text>
        </xsl:if>
        <xsl:if test="@Style">
          <i>
            <xsl:value-of select="@Style"/>
          </i>
        </xsl:if>
        <xsl:if test="@New and @New = 'true'">
          <b> * NEW *</b>
        </xsl:if>
      </td>
      <td>
        <xsl:choose>
          <xsl:when test="@Small">
            <xsl:text>£</xsl:text>
            <xsl:value-of select="@Small"/>
          </xsl:when>
          <xsl:otherwise>-&#160;&#160;&#160;</xsl:otherwise>
        </xsl:choose>
      </td>
      <td>
        <xsl:choose>
          <xsl:when test="@Large">
            <xsl:text>£</xsl:text>
            <xsl:value-of select="@Large"/>
          </xsl:when>
          <xsl:otherwise>-&#160;&#160;&#160;</xsl:otherwise>
        </xsl:choose>
      </td>
      <td>
        <xsl:choose>
          <xsl:when test="@Bottle | @Carafe">
            <xsl:text>£</xsl:text>
            <xsl:value-of select="@Bottle | @Carafe"/>
          </xsl:when>
          <xsl:otherwise>-&#160;&#160;&#160;</xsl:otherwise>
        </xsl:choose>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet> 
