<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"   
    xmlns:java="http://xml.apache.org/xslt/java"
    exclude-result-prefixes="java">
<xsl:output indent="yes" method="html"/>
<xsl:template match="egbokdoc">
<html>
 <head>
  <style type="text/css">
  <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
  tr.copyright, tr.maintainer, td.footnotes, span.footnote
    {font-size: small; font-weight: bold;}
  td.caption {font-size: x-small; font-weight: bold;}
  td.reftitle {font-size: large; font-weight: bold;}
  div.poetry {margin-left: 40px; font-style: italic; font-weight: bold;}
  div.poetry-title {margin-left: 40px; font-size: large; font-style: italic; font-weight: bold;}
  <xsl:text disable-output-escaping="yes">--&gt;</xsl:text>
  </style>
  <xsl:apply-templates select="title" mode="header"/>
  <link rel="icon" href="/Favicon.ICO"/>
  <link rel="SHORTCUT ICON" href="/Favicon.ICO"/>

 </head>
 <body bgcolor="#ffffff" lang="EN-US" link="#339999" vlink="#333366" alink="#999966">

  <xsl:variable name="content_width">
      <xsl:choose>
        <xsl:when test="//reference">
	   <xsl:text>500</xsl:text>
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>770</xsl:text>
        </xsl:otherwise>
     </xsl:choose>
  </xsl:variable>
  <xsl:variable name="reference_width">
      <xsl:choose>
        <xsl:when test="//reference">
	   <xsl:text>280</xsl:text>
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>10</xsl:text>
        </xsl:otherwise>
     </xsl:choose>
  </xsl:variable>
    <!-- Title Bar -->
    <table width="800">
 	<tr>
	  <td rowspan="2">
           <a href="http://www.egbok.com">
	   <img src="http://www.egbok.com/images/Egbok.gif" 
		alt="EGBOK Consultants" 
		width="100" 
		height="108" 
		border="0" />
	  </a>
	  </td>
	  <td><h1 align="left">
	    <xsl:apply-templates select="title" mode="title"/>
          </h1></td>
	  <td rowspan="2">
	   <xsl:apply-templates select="righthand_image"/>
          </td>
	</tr>
        <tr><td>
	<h2><xsl:apply-templates select="subtitle"/></h2>
        </td>

</tr>
    </table>
	<table width="800">
	<tr colspan="3" class="copyright"><td>
	<xsl:apply-templates select="copyright"/>
	</td></tr>
	<tr><td colspan="3"><hr/></td></tr>
	<td width="{$content_width}" valign="top">
	<xsl:apply-templates select="content" />
	</td>
	<td width="20">&#160;</td>
        <td width="{$reference_width}" valign="top">
        <p>&#160;</p>
	<xsl:apply-templates select="references" />
        </td>
	<tr><td colspan="3"><hr/></td></tr>
	<xsl:call-template name="footnotes" />
	<tr class="maintainer"><td>
      Document Maintainer: <xsl:apply-templates select="maintainer" />
       <xsl:variable name="date"
		select="java:java.util.Date.new(	)" />
       <xsl:variable name="formatter"	
		select="java:java.text.SimpleDateFormat.new()"/>

       Last Updated <xsl:value-of
	   select="java:format($formatter, $date)" />
       </td></tr>
	</table>
</body>
</html>
</xsl:template>

<xsl:template match="table">
   <xsl:variable name="border">
      <xsl:choose>
        <xsl:when test="@border">
           <xsl:value-of select="@border" />
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>0</xsl:text>
        </xsl:otherwise>
     </xsl:choose>
  </xsl:variable>
   <xsl:variable name="cellpadding">
      <xsl:choose>
        <xsl:when test="@cellpadding">
           <xsl:value-of select="@cellpadding" />
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>0</xsl:text>
        </xsl:otherwise>
     </xsl:choose>
  </xsl:variable>
  <table border="{$border}" cellpadding="{$cellpadding}">
    <xsl:apply-templates />
  </table>
</xsl:template>

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

<xsl:template match="td">
   <xsl:variable name="align">
      <xsl:choose>
        <xsl:when test="@align">
           <xsl:value-of select="@align"/>
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>left</xsl:text>
        </xsl:otherwise>
     </xsl:choose>
  </xsl:variable>
   <xsl:variable name="valign">
      <xsl:choose>
        <xsl:when test="@valign">
           <xsl:value-of select="@valign"/>
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>top</xsl:text>
        </xsl:otherwise>
     </xsl:choose>
  </xsl:variable>
  <td align="{$align}" valign="{$valign}">
    <xsl:apply-templates />
  </td>
</xsl:template>

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

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

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

<xsl:template match="maintainer">
  <xsl:apply-templates select="name"/>
   (<a href="mailto:{email}"><xsl:value-of select="email"/></a>)
</xsl:template>

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


<xsl:template match="maintainer/affiliation">
</xsl:template>

<xsl:template match="title" mode="header">
    <title><xsl:apply-templates/></title>
</xsl:template>

<xsl:template match="title" mode="title">
    <xsl:apply-templates/>
   <xsl:if test="/subtitle">:</xsl:if>
</xsl:template>

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

 <xsl:template match="content">
    <table>
       <xsl:apply-templates/>
   </table>
 </xsl:template>

<xsl:template match="section">
     <tr><td>&#160;</td></tr>
     <tr><td align="left"><h2><xsl:value-of select="@title"/></h2></td></tr>
     <tr><td>
     <xsl:choose>
	<xsl:when test="@img">
	 <img src="{@img}"/>
	</xsl:when>
 	<xsl:otherwise>
     	  &#160;
 	</xsl:otherwise>
     </xsl:choose>
     </td></tr>
     <xsl:apply-templates/>
</xsl:template>

<xsl:template match="subsection">
     <tr><td>&#160;</td></tr>
     <tr><td align="left"><h3><xsl:value-of select="@title"/></h3></td></tr>
     <tr><td>&#160;</td></tr>
     <xsl:apply-templates/>
</xsl:template>

<xsl:template match="subsubsection">
     <tr><td>&#160;</td></tr>
     <tr><td align="left"><h4><xsl:value-of select="@title"/></h4></td></tr>
     <tr><td>&#160;</td></tr>
     <xsl:apply-templates/>
</xsl:template>

 <xsl:template match="para">
    <tr><td>
    <p><xsl:apply-templates/></p>
    </td></tr>
 </xsl:template>

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

<xsl:template match="poetry">
  <tr><td>
  <p>
   <br/>
   <div class="poetry-title"><xsl:value-of select="@title" /></div>
   <br/>
   <xsl:apply-templates/>
  </p>
  </td></tr>
</xsl:template>

<xsl:template match="poetry/line">
   <div class="poetry">
     <xsl:apply-templates/>
   </div>
</xsl:template>

<xsl:template match="em">
  <i><xsl:apply-templates/></i>
</xsl:template>

<xsl:template match="strong">
  <b><i><xsl:apply-templates/></i></b>
</xsl:template>

 <xsl:template match="link">
   <xsl:variable name="target">
      <xsl:choose>
        <xsl:when test="@text">
           <xsl:value-of select="@text"/>
        </xsl:when>
        <xsl:when test="@img">
           <xsl:text disable-output-escaping="yes">
             &lt;
           </xsl:text>
           img src="{@img}"
           <xsl:text disable-output-escaping="yes">
             &gt;
           </xsl:text>
        </xsl:when>
     </xsl:choose>
  </xsl:variable>

   <a href="{@href}"><xsl:value-of select="$target" /></a>

 </xsl:template>


 <xsl:template match="img">
      <xsl:choose>
        <xsl:when test="@caption">
	  <table border="0" cellpadding="0"> 
            <tr>
              <td>
               <xsl:text disable-output-escaping="yes">
                &lt;img src="</xsl:text><xsl:value-of select="@src" /><xsl:text disable-output-escaping="yes">"&gt;
               </xsl:text>
              </td>
            </tr>
            <tr>
             <td class="caption">
              <xsl:value-of select="@caption" />
             </td>
            </tr>
           </table>
        </xsl:when>
        <xsl:otherwise>
         <xsl:text disable-output-escaping="yes">
          &lt;img src="</xsl:text><xsl:value-of select="@src" /><xsl:text disable-output-escaping="yes">"&gt;
         </xsl:text>
        </xsl:otherwise>
     </xsl:choose>


 </xsl:template>

 <xsl:template match="gexample">
   <xsl:choose>
     <xsl:when test="@name">
        <a name="{@name}" />
     </xsl:when>
   </xsl:choose>

   <p>&#160;</p>
   <p>

      <xsl:choose>
        <xsl:when test="@caption">
	  <table border="0" cellpadding="0"> 
            <tr>
              <td>
               <xsl:text disable-output-escaping="yes">
                &lt;img src="</xsl:text><xsl:value-of select="@src" /><xsl:text disable-output-escaping="yes">"&gt;
               </xsl:text>
              </td>
            </tr>
            <tr>
             <td class="caption">
              <xsl:value-of select="@caption" />
             </td>
            </tr>
           </table>
        </xsl:when>
        <xsl:otherwise>
         <xsl:text disable-output-escaping="yes">
          &lt;img src="</xsl:text><xsl:value-of select="@src" /><xsl:text disable-output-escaping="yes">"&gt;
         </xsl:text>
        </xsl:otherwise>
     </xsl:choose>

   </p>
   <p>&#160;</p>
 </xsl:template>

 <xsl:template match="target">
   <a name="{@name}" />
 </xsl:template>

 <xsl:template match="citation">
   <a href="{@href}"><b><i><xsl:value-of select="@title"/></i></b> by  <xsl:value-of select="@author"/></a>
 </xsl:template>

<xsl:template match="footnote">
  <a name="{@ref}-src"/>
  <a href="#{@ref}">
   <span class="footnote"><sup><xsl:value-of select="@ref"/></sup></span></a>
</xsl:template>


<xsl:template name="footnotes">
  <xsl:if test="//footnote">
    <tr><td colspan="3" class="footnotes">Footnotes</td></tr>
    <xsl:for-each select="//footnote">
      <tr><td colspan="3" class="footnotes">
       <a href="#{@ref}-src"><xsl:value-of select="@ref"/></a>
       <a name="{@ref}"/>
       &#160;<xsl:apply-templates /></td></tr>
    </xsl:for-each>
    <tr><td colspan="3">&#160;</td></tr>
  </xsl:if>
</xsl:template>

<xsl:template match="references">
   <xsl:variable name="reftitle">
      <xsl:choose>
        <xsl:when test="@title">
           <xsl:value-of select="@title"/>
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>References</xsl:text>
        </xsl:otherwise>
     </xsl:choose>
   </xsl:variable>

   <table><tr><td colspan="2" class="reftitle"><xsl:value-of select="$reftitle"/></td></tr>
	<xsl:apply-templates  />
   </table>
</xsl:template>

<xsl:template match="reference">
  <tr>
    <td>&#160;</td>
    <td><a href="{@href}"><xsl:value-of select="@text" /></a>
      <xsl:if test="@extratext">
         &#160;<xsl:value-of select="@extratext"/>
      </xsl:if>
  </td></tr>
</xsl:template>
<xsl:template match="righthand_image">
  <xsl:choose>
	<xsl:when test="@href">
		<a href="{@href}">
	  	<img src="{@src}" 
		     alt="{@alt}"
		     border="0"
		     width="{@width}" 
		     height="{@height}" />
		</a>
	</xsl:when>
	<xsl:otherwise>
	  	<img src="{@src}" 
		     alt="{@alt}" 
		     border="0"
		     width="{@width}" 
		     height="{@height}" />
	</xsl:otherwise>
  </xsl:choose>
</xsl:template>

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

</xsl:stylesheet>
