<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:doc="http://www.aasted.org/DOCUMENT">

<xsl:param name="ch"> 0 </xsl:param>

<xsl:template match="doc:document">

    <html>
    <head> <title> <xsl:value-of select="@title"/> </title> </head>    
    
    <style>
        a.mail {
            color: rgb(255,255,255);
            text-decoration: none;
        }
                    
        a:visited {
            color: rgb(0,0,255);
            text-decoration: none;
        }
        
        a {
            color: rgb(0,0,255);
            text-decoration: none;
        }
        
        a:hover {
            color: rgb(51,153,255);
            text-decoration: underline;
        }
        
    </style>
    
    <body style="text-align: left; font-family: sans-serif;">    
        <div style="font-size: medium; text-align: center;">
            <b><xsl:value-of select="@title"/></b>
        </div>
        <div style="font-size: small; text-align:center; font-family: sans-serif;">
            <xsl:variable name="mail" select="doc:author/doc:e-mail"/>        
            <a href="mailto:{$mail}"> <xsl:value-of select="doc:author/text()"/></a>
        </div>  
       
        <div style="padding: 1em;">
        </div>
        <xsl:if test="number($ch) = 0">
            <xsl:apply-templates select="doc:chapter"/>
        </xsl:if>
        <xsl:if test="not(number($ch) = 0)">
            <xsl:apply-templates select="doc:chapter[number($ch) = position()]"/>
        </xsl:if>
<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));</script><script type="text/javascript">var pageTracker = _gat._getTracker("UA-3773432-1");pageTracker._initData();pageTracker._trackPageview();</script>
    </body>    
    </html>    
</xsl:template>

<xsl:template match="doc:chapter">
    <xsl:if test="not(number($ch) = 0)">
        <!-- Make links to surrounding chapters -->
        <table style="width=90%; font-size: x-small;"><tr>
        
        <td style="text-align:left;">
        <xsl:if test="preceding-sibling::doc:chapter">
            <xsl:variable name="prevch" select="count(preceding::doc:chapter)"/>
            
            <a href="content.php?ch={$prevch}">&lt;&lt; <xsl:value-of select="preceding-sibling::doc:chapter[1]/@title"/></a>
        </xsl:if>
        </td>
        
        <td style="text-align: right;">
        <xsl:if test="following-sibling::doc:chapter">
            <xsl:variable name="nextch" select="count(preceding::doc:chapter) + 2"/>
        
            <a href="content.php?ch={$nextch}"><xsl:value-of select="following-sibling::doc:chapter[1]/@title"/> &gt;&gt;</a>
        </xsl:if>
        </td>
        
        </tr></table>
    </xsl:if>
    
    <div style="padding-left: 3em; margin-top: 2em; margin-bottom: 1em; text-align: left; font-style: sans-serif; font-variant: small-caps; font-size: large;">
        <xsl:value-of select="count(preceding::doc:chapter) + 1"/>. <xsl:value-of select="@title"/>
    </div>
    <xsl:apply-templates select="doc:section | doc:example"/>

    <xsl:if test="not(number($ch) = 0)">
        <!-- Make links to surrounding chapters -->
        <table style="margin-top: 2em; width=90%; font-size: x-small;"><tr>
        
        <td style="text-align:left;">
        <xsl:if test="preceding-sibling::doc:chapter">
            <xsl:variable name="prevch" select="count(preceding::doc:chapter)"/>
            
            <a href="content.php?ch={$prevch}">&lt;&lt; <xsl:value-of select="preceding-sibling::doc:chapter[1]/@title"/></a>
        </xsl:if>
        </td>
        <td style="text-align: right;">
        <xsl:if test="following-sibling::doc:chapter">
            <xsl:variable name="nextch" select="count(preceding::doc:chapter) + 2"/>
        
            <a href="content.php?ch={$nextch}"><xsl:value-of select="following-sibling::doc:chapter[1]/@title"/> &gt;&gt;</a>
        </xsl:if>
        </td>
        
        </tr></table>
        <div style="width: 100%; text-align: center;">
            <a href="index.php">Index</a>
        </div>
    </xsl:if>
</xsl:template>

<xsl:template match="doc:section">
    <xsl:if test="@title">
        <div style="margin-left: 1em; font: sans-serif; margin-bottom: 1em;">
            <b><xsl:value-of select="@title"/></b>
        </div>
    </xsl:if>
    <div style="padding-bottom: 1em; font: sans-serif;">
        <xsl:copy-of select="."/>
    </div>
</xsl:template>

<xsl:template match="doc:example">
        <pre style="padding: 0em; margin: 0em; margin-left: 1em; margin-bottom: 1em;">
            <xsl:copy-of select="."/>
        </pre>
</xsl:template>

</xsl:stylesheet>
