<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:include href="chunk.mod"/>
<xsl:include href="param.mod"/>

<xsl:output method="html" indent="yes"/>


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


<xsl:template match="article">
  <xsl:document href="{$output.path}/index.html">

    <html>
      <head><title><xsl:value-of select="title"/></title>
      <LINK rel="stylesheet" type="text/css" href="{$css.path}"/>
    </head>
    <body bgcolor="#ffffff" background="{$main.background}">
      <table cellpadding="20">
        <tr>
          <td>
            <table cols="2">
              <xsl:apply-templates/>
            </table>
          </td>
        </tr>
      </table>
    </body>
  </html>
</xsl:document>
</xsl:template>

<xsl:template match="articleinfo">
  <tr>
    <td colspan="2">
      <xsl:apply-templates/>
    </td>
  </tr>
</xsl:template>

<xsl:template match="title">
  <tr>
    <td colspan="2">
      <img SRC="{$page.icon}" align="left"/>
      <h1 align="center"><xsl:apply-templates/></h1>
    </td>
  </tr>
</xsl:template>

<xsl:template match="copyright">
  <p>Copyright &#xA9; <xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="sect1[position() &lt;= round( last() div 2)]">

  <xsl:variable name="sections">
    <xsl:value-of select="round(count(../sect1) div 2)"/>
  </xsl:variable>
  <xsl:variable name="next">
    <xsl:value-of select="count(preceding-sibling::*) - 1"/>
  </xsl:variable>

  <!--  <xsl:message>sections: <xsl:value-of select="$sections"/>
round(count(../sect1): <xsl:value-of select="round(count(../sect1))"/>
count(preceding-sibling::*): <xsl:value-of select="count(preceding-sibling::*)"/>
processing <xsl:value-of select="@id"/>: <xsl:number select="position()"/> next: <xsl:value-of select="$next + $sections"/>  </xsl:message>
-->
  <tr>
    <td>
      <p><xsl:apply-templates select="." mode="titlepage"/></p>
    </td>
    <td>
      <p><xsl:apply-templates select="//sect1[position() = $next + $sections]" mode="titlepage"/></p>
    </td>
  </tr>

</xsl:template>

<xsl:template match="sect1[position() > ((last() +1) div 2)]">
</xsl:template>

<xsl:template match="sect1" mode="titlepage">
  <a>
    <xsl:attribute name="href"><xsl:value-of select="@id"/>.html</xsl:attribute>
    <xsl:number count="sect1"/>. <xsl:value-of select="title"/>
  </a>
  <xsl:call-template name="write.chunk">
    <xsl:with-param name="filename">
      <xsl:value-of select="@id"/>.html</xsl:with-param>
      <xsl:with-param name="content">

      <html>
        <head><title><xsl:value-of select="title"/></title>
	  <LINK rel="stylesheet" type="text/css" href="pres.css"/>
	</head>
	  <body bgcolor="#ffffff" background="{$page.background}">
      <table COLS="1" WIDTH="100%" HEIGHT="100%" cellpadding="20">
        <tr>
          <td>
	    <table COLS="1" WIDTH="100%" HEIGHT="100%">
	    <tr><td HEIGHT="90%" valign="top">
	      <xsl:apply-templates/></td></tr>
	    <tr><td HEIGHT="1%">

	      <xsl:call-template name="chunk.footer">
	        <xsl:with-param name="prev" select="preceding::sect1[1]"/>
		<xsl:with-param name="next" select="following::sect1[1]"/>
	      </xsl:call-template>
	    </td></tr>
	    </table>
	    </td></tr>
	    </table>
	  </body>
      </html>

    </xsl:with-param>
    <xsl:with-param name="prev" select="preceding::sect1[1]"/>
    <xsl:with-param name="next" select="following::sect1[1]"/>
  </xsl:call-template>

</xsl:template>

<xsl:template match="sect1/title">
  <table width="100%" cols="2">
    <tr>
      <td width="5%"><img SRC="{$page.icon}"/></td>
      <td width="95%" valign="top" align="center"><h2><xsl:number count="sect1"/>. <xsl:apply-templates/></h2></td>
    </tr>
  </table>
</xsl:template>

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

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

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

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

<xsl:template match="imagedata">
  <img>
	<xsl:attribute name="src"><xsl:value-of select="@fileref"/></xsl:attribute>
  </img>

</xsl:template>

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

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

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

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

<xsl:template match="itemizedlist/listitem">
<p>
  <img SRC="{$item.icon}"/>
  <xsl:apply-templates/>
</p>
</xsl:template>

<xsl:template match="programlisting">

  <blockquote>
    <table BGCOLOR="#DDDDDD">
      <tr>
        <td><pre><xsl:value-of select ="."/></pre></td>
      </tr>
    </table>
  </blockquote>
</xsl:template>

<xsl:template match="informaltable">
  <table>
    <xsl:apply-templates select ="tgroup/tbody/row"/>
  </table>
</xsl:template>

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

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

<xsl:template match="ulink">
  <a href="{@url}"><xsl:value-of select ="."/><!--
  (<xsl:value-of select ="@url"/>)--></a>
</xsl:template>

<!-- ignore appendices -->

<xsl:template match="appendix">
</xsl:template>

<!-- ignore stuff for booklets only -->

<xsl:template match="*[@condition='booklet']">
</xsl:template>

</xsl:stylesheet>
