<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:bridge="http://www.thomaso.com/xmlns/bridge"
                exclude-result-prefixes="bridge xsl">

<xsl:param name="serverSide" select="'no'"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="/bridge:article/bridge:title"/></title>
<link rel="stylesheet" type="text/css" href="/css/article.css"/>
<link rel="stylesheet" type="text/css" href="local.css"/>
<xsl:if test="$serverSide='yes'">
<link rel="Validate" title="HTML Validate"
                href="http://validator.w3.org/check/referer"/>
<link rel="Validate" title="CSS Validate"
                href="http://jigsaw.w3.org/css-validator/check/referer"/>
</xsl:if>

</head>
<body>
<div class="back">Return to <a href="./">XML and Bridge</a></div>
<div class="body">
<h2>Format notes</h2>
<div class="stylecomment"><xsl:copy-of select="$stylecomment"/></div>
<xsl:apply-templates select="/bridge:article"/>
</div>
<div class="sig">
<address> <a NAME="mysig"> <xsl:value-of select="/bridge:article/bridge:author"/></a>
(<a><xsl:attribute name="href">mailto:<xsl:value-of select="bridge:article/bridge:author/@email"/></xsl:attribute>
<xsl:value-of select="bridge:article/bridge:author/@email"/></a>),
Copyright <xsl:value-of select="bridge:article/bridge:copyright"/>.
</address>
</div>
</body>
</html>
</xsl:template>

<xsl:template match="bridge:article">
<xsl:apply-templates select="bridge:title"/>
<xsl:apply-templates select="bridge:body"/> 
</xsl:template>

<xsl:template match="bridge:body">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="bridge:title">
<h1><xsl:apply-templates/></h1>
</xsl:template>

<xsl:template name="holding">
<xsl:param name="attr"/>
<xsl:choose>
<xsl:when test="string($attr)">
    <xsl:call-template name="holdingcards">
    <xsl:with-param name="cards" select="$attr"/>
    </xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:copy-of select="$void"/></xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="holdingcards">
<xsl:param name="cards"/>
<xsl:param name="recurse" value="0"/>
<xsl:if test="$recurse and string-length($cards)!=0">&#xA0;</xsl:if>
<xsl:choose>
<xsl:when test="string-length($cards)=0"></xsl:when>
<xsl:when test="substring($cards,1,1)='^'">
<span class='played'>
<xsl:call-template name="card">
<xsl:with-param name="card" select="substring($cards,2,1)"/>
</xsl:call-template>
</span>
<xsl:call-template name="holdingcards">
<xsl:with-param name="cards" select="substring($cards,3)"/>
<xsl:with-param name="recurse" select="1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="card">
<xsl:with-param name="card" select="substring($cards,1,1)"/>
</xsl:call-template>
<xsl:call-template name="holdingcards">
<xsl:with-param name="cards" select="substring($cards,2)"/>
<xsl:with-param name="recurse" select="1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="card">
<xsl:param name="card"/>
<xsl:choose>
<xsl:when test="$card='T'">
<xsl:copy-of select="$ten"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate($card,'AKQJ',$honors)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="writehand">
<table class="hand" cellpadding="0" cellspacing="0" border="0">
<xsl:if test="@sp">
<tr>
<td class="suitsym"><xsl:copy-of select="$spade"/></td>
<td class="holding"><xsl:call-template name="holding">
	<xsl:with-param name="attr" select="@sp"/>
   </xsl:call-template></td></tr>
</xsl:if>

<xsl:if test="@he">
<tr><td class="suitsym"><xsl:copy-of select="$heart"/></td>
    <td class="holding"><xsl:call-template name="holding">
	<xsl:with-param name="attr" select="@he"/>
   </xsl:call-template></td></tr>
</xsl:if>

<xsl:if test="@di">
<tr><td class="suitsym"><xsl:copy-of select="$diamond"/></td>
   <td class="holding"><xsl:call-template name="holding">
	<xsl:with-param name="attr" select="@di"/>
   </xsl:call-template></td></tr>
</xsl:if>

<xsl:if test="@cl">
<tr><td class="suitsym"><xsl:copy-of select="$club"/></td>
   <td class="holding"><xsl:call-template name="holding">
	<xsl:with-param name="attr" select="@cl"/>
   </xsl:call-template></td></tr>
</xsl:if>
</table>

</xsl:template>

<xsl:template match="bridge:author"></xsl:template>

<xsl:template match="bridge:programdata">
</xsl:template>

<xsl:template match="bridge:hand">
	<xsl:call-template name="writehand"/>
</xsl:template>

<xsl:template match="bridge:diagram">
<table class="diagram" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="width:10%;"/>
<td style="width:10%;"/>
<td style="width:10%;"/>
<td style="width:10%;"/>
<td style="width:10%;"/>
<td style="width:10%;"/>
<td style="width:10%;"/>
<td style="width:10%;"/>
<td style="width:10%;"/>
<td style="width:10%;"/>
</tr>
<tr valign="bottom">

<td colspan="3" style="width:30%;"/>
<td colspan="4" style="width:40%;"><xsl:apply-templates select="bridge:hand[@seat='north']"/></td>
<td colspan="3" style="width:30%;"/>
</tr><tr>
<td colspan="4" style="width:40%;"><xsl:apply-templates select="bridge:hand[@seat='west']"/></td>
<td colspan="2" style="width:20%;">&#xA0;</td>
<td colspan="4" style="width:40%;"><xsl:apply-templates select="bridge:hand[@seat='east']"/></td>
</tr><tr valign="top">
<td colspan="3" style="width:30%"/>
<td colspan="4" style="width:40%;"><xsl:apply-templates select="bridge:hand[@seat='south']"/></td>
<td colspan="3"/>
</tr>
</table>
</xsl:template>

<xsl:template match="bridge:a[@name]">
<a><xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute><xsl:apply-templates/></a>
</xsl:template>

<xsl:template match="bridge:a[@href]">
<a target="_top"><xsl:attribute name="href">
<xsl:value-of select="@href"/>
</xsl:attribute><xsl:apply-templates/></a>
</xsl:template>

<xsl:template match="bridge:chapter">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="bridge:h2">
<h3><xsl:apply-templates/></h3>
</xsl:template>

<xsl:template match="bridge:h3">
<h4><xsl:apply-templates/></h4>
</xsl:template>

<xsl:template match="bridge:club">
<xsl:copy-of select="$club"/><xsl:call-template name="holdingcards">
<xsl:with-param name="cards" select="@cards"/>
</xsl:call-template><xsl:apply-templates/>
</xsl:template>

<xsl:template match="bridge:diamond">
<xsl:copy-of select="$diamond"/><xsl:call-template name="holdingcards">
<xsl:with-param name="cards" select="@cards"/>
</xsl:call-template><xsl:apply-templates/>
</xsl:template>

<xsl:template match="bridge:heart">
<xsl:copy-of select="$heart"/><xsl:call-template name="holdingcards">
<xsl:with-param name="cards" select="@cards"/>
</xsl:call-template><xsl:apply-templates/>
</xsl:template>

<xsl:template match="bridge:spade">
<xsl:copy-of select="$spade"/><xsl:call-template name="holdingcards">
<xsl:with-param name="cards" select="@cards"/>
</xsl:call-template><xsl:apply-templates/>
</xsl:template>

<xsl:template match="bridge:holding">
<xsl:call-template name="holdingcards">
<xsl:with-param name="cards" select="@cards"/>
</xsl:call-template><xsl:apply-templates/>
</xsl:template>

<xsl:template match="bridge:p">
<div class="p"><xsl:apply-templates/></div><br/>
</xsl:template>

<xsl:template match="bridge:div">
<div><xsl:apply-templates/></div>
</xsl:template>

<xsl:template match="*">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>

</xsl:stylesheet>
