<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output encoding="iso-8859-1"/>

<xsl:template match="/">
 <html>
  <head>
    <title><xsl:value-of select="proofSystem/@title"/></title>
  </head>
  <body>
    <h1><xsl:value-of select="proofSystem/@title"/></h1>
    <xsl:apply-templates/>
  </body>
 </html>
</xsl:template>

<xsl:template match="proofSystem">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="notation">
 <h2>Notation</h2>
 <table border="1">
  <tr>
   <th>Notation</th>
   <th>Meaning</th>
  </tr>
<xsl:apply-templates/></table>
  <h2>Inference Rules</h2>
</xsl:template>

<xsl:template match="item">
  <tr>
   <td align="center"><xsl:apply-templates select="*[1]"/></td>
   <td><xsl:apply-templates select="*[position()!=1]|text()"/></td>
  </tr>
</xsl:template>

<xsl:template match="rule">
  <table cellspacing="20">
    <tr valign="center">
      <td>(<xsl:value-of select="@name"/>)</td>
      <td>
	<xsl:variable name="ncols" select="count(*) - 1"/>
	<table cellpadding="0" cellspacing="0">
          <xsl:if test="$ncols">
	    <tr align="center" width="100%">
	      <xsl:for-each select="*[position() != last()]">
		<td>
                   <xsl:if test="position() != 1">&#160;&#160;&#160;&#160;</xsl:if>
 		   <xsl:apply-templates select="."/>
		</td>
	      </xsl:for-each>
	    </tr>
	    <tr><td colspan="{$ncols}"><hr noshade="noshade"/></td></tr>
          </xsl:if>
	  <tr align="center">
	    <td colspan="{$ncols}">
	      <xsl:apply-templates select="*[last()]"/>
	    </td>
	  </tr>
	</table>
      </td>
    </tr>
  </table>
</xsl:template>

<xsl:template match="rule" mode="ignore">
<table align="center">
<tr>
<td colspan="2" align="center">
Rule <xsl:value-of select="@name"/>
</td>
</tr>
<xsl:if test="count(*)=1">
<tr>
<td>If</td>
<td></td>
</tr>
</xsl:if>
<xsl:for-each select="*">
<tr  valign="baseline">
<td>
<xsl:choose>
<xsl:when test="position()=last()">then</xsl:when>
<xsl:when test="position()=1">If</xsl:when>
<xsl:otherwise>and</xsl:otherwise>
</xsl:choose>
</td>
<td>
<xsl:apply-templates select="."/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>


<xsl:template match="judgement[@name='match']">
  <xsl:apply-templates select="*[1]"/>
  <xsl:text>; </xsl:text>
  <xsl:apply-templates select="*[2]"/>
  <xsl:text> |- </xsl:text>
  <xsl:apply-templates select="*[3]"/>
  <xsl:text>; </xsl:text>
  <xsl:apply-templates select="*[4]"/>
  <xsl:text> =~ </xsl:text>
  <xsl:apply-templates select="*[5]"/>
  <xsl:text> => </xsl:text>
  <xsl:apply-templates select="*[6]"/>
  <xsl:text>; </xsl:text>
  <xsl:apply-templates select="*[7]"/>
</xsl:template>

<xsl:template match="judgement[@name='belongs']">
  <xsl:apply-templates select="*[1]"/>
  <xsl:text> in </xsl:text>
  <xsl:apply-templates select="*[2]"/>
</xsl:template>

<xsl:template match="judgement[@name='subset']">
  <xsl:apply-templates select="*[1]"/>
  <xsl:text> subset </xsl:text>
  <xsl:apply-templates select="*[2]"/>
</xsl:template>

<xsl:template match="judgement[@name='interleave']">
  <xsl:apply-templates select="*[1]"/>
  <xsl:text> interleaves </xsl:text>
  <xsl:apply-templates select="*[2]"/>
  <xsl:text>; </xsl:text>
  <xsl:apply-templates select="*[3]"/>
</xsl:template>

<xsl:template match="judgement[@name='whiteSpace']">
  <xsl:text>WS( </xsl:text>
  <xsl:apply-templates select="*"/>
  <xsl:text> )</xsl:text>
</xsl:template>

<xsl:template match="judgement">
  <xsl:value-of select="@name"/>
  <xsl:text>(</xsl:text>
  <xsl:for-each select="*">
    <xsl:if test="position()!=1">
      <xsl:text>, </xsl:text>
    </xsl:if>
    <xsl:apply-templates select="."/>
  </xsl:for-each>
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="judgement[@name='equal']">
  <xsl:apply-templates select="*[1]"/>
  <xsl:text> = </xsl:text>
  <xsl:apply-templates select="*[2]"/>
</xsl:template>

<xsl:template match="judgement[@name='binds']">
  <xsl:apply-templates select="*[1]"/>
  <xsl:text>.</xsl:text>
  <xsl:apply-templates select="*[2]"/>
  <xsl:text> = </xsl:text>
  <xsl:apply-templates select="*[3]"/>
</xsl:template>

<xsl:template match="not">
   <xsl:text>not(</xsl:text>
     <xsl:apply-templates select="*"/>
   <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="function">
  <xsl:value-of select="@name"/>
  <xsl:text>( </xsl:text>
  <xsl:for-each select="*">
    <xsl:if test="position() != 1">
      <xsl:text>, </xsl:text>
    </xsl:if>
    <xsl:apply-templates select="."/>
  </xsl:for-each>
  <xsl:text> )</xsl:text>
</xsl:template>

<xsl:template match="var">
  <xsl:apply-templates select="@range"/>
  <xsl:if test="@sub">
    <sub><xsl:value-of select="@sub"/></sub>
  </xsl:if>
</xsl:template>

<xsl:template match="element">
  <xsl:choose>
    <xsl:when test="not(*[not(self::attribute|self::namespaceMap)])">
      <code>&lt;<xsl:value-of select="@name"/></code>
        <xsl:apply-templates select="attribute" mode="start-tag"/>
      <code>/&gt;</code>
    </xsl:when>
    <xsl:otherwise>
      <code>&lt;<xsl:value-of select="@name"/></code>
        <xsl:apply-templates select="attribute|namespaceMap" mode="start-tag"/>
      <code>&gt;</code>
	<xsl:for-each select="*[not(self::attribute|self::namespaceMap)]">
	  <xsl:text> </xsl:text>
	  <xsl:apply-templates select="."/>
	</xsl:for-each>
	<xsl:text> </xsl:text>
      <code>&lt;/<xsl:value-of select="@name"/>&gt;</code>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="group">
  <xsl:for-each select="*">
    <xsl:if test="position() != 1">
      <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:apply-templates select="."/>
  </xsl:for-each>
</xsl:template>

<xsl:template match="attribute" mode="start-tag">
  <code>
    <xsl:text> </xsl:text>
    <xsl:value-of select="@name"/>
    <xsl:text>="</xsl:text>
  </code>
    <xsl:apply-templates select="*"/>
  <code>"</code>
</xsl:template>

<xsl:template match="namespaceMap" mode="start-tag">
  <code><xsl:text> </xsl:text></code>
  <xsl:apply-templates select="."/>
</xsl:template>

<xsl:template match="namespaceMap">
  <xsl:text>{</xsl:text>
  <xsl:apply-templates select="*"/>
  <xsl:text>}</xsl:text>
</xsl:template>

<xsl:template match="string">
  <code><xsl:value-of select="."/></code>
</xsl:template>

<xsl:template match="@range">
 <i><xsl:value-of select="."/></i>
</xsl:template>

<xsl:template match="@range[.='pattern']">
 <i>p</i>
</xsl:template>

<xsl:template match="@range[.='keybag']">
 <i>k</i>
</xsl:template>

<xsl:template match="@range[.='keyrefbag']">
 <i>kr</i>
</xsl:template>

<xsl:template match="@range[.='att']">
 <i>a</i>
</xsl:template>

<xsl:template match="@range[.='mixed']">
 <i>m</i>
</xsl:template>

<xsl:template match="@range[.='string']">
 <i>s</i>
</xsl:template>

<xsl:template match="@range[.='attval']">
 <i>v</i>
</xsl:template>

<xsl:template match="@range[.='nameClass']">
 <i>nc</i>
</xsl:template>

<xsl:template match="@range[.='name']">
 <i>n</i>
</xsl:template>

<xsl:template match="@range[.='ncname']">
 <i>ln</i>
</xsl:template>

<xsl:template match="@range[.='namespaceMap']">
 <i>ns</i>
</xsl:template>

<xsl:template match="@range[.='uri']">
 <i>u</i>
</xsl:template>

<xsl:template match="@range[.='env']">
  <i>E</i>
</xsl:template>

<xsl:template match="function[@name='emptyBag']">
 <xsl:text>{ }</xsl:text>
</xsl:template>

<xsl:template match="function[@name='emptyEnv']">
 <xsl:text>env()</xsl:text>
</xsl:template>

<xsl:template match="function[@name='emptyNamespaceMap']">
 <xsl:text>ns()</xsl:text>
</xsl:template>

<xsl:template match="function[@name='emptySequence']">
 <xsl:text>( )</xsl:text>
</xsl:template>

<xsl:template match="function[@name='emptyString']">
 <xsl:text>""</xsl:text>
</xsl:template>

<xsl:template match="function[@name='union']">
  <xsl:for-each select="*">
    <xsl:if test="position() != 1">
      <xsl:text> + </xsl:text>
    </xsl:if>
    <xsl:apply-templates select="."/>
  </xsl:for-each>
</xsl:template>

<xsl:template match="function[@name='append']">
  <xsl:for-each select="*">
    <xsl:if test="position() != 1">
      <xsl:text>, </xsl:text>
    </xsl:if>
    <xsl:apply-templates select="."/>
  </xsl:for-each>
</xsl:template>


</xsl:stylesheet>
