<?xml version="1.0"?>
<!--
      wedig.xsl, by Jelks Cabaniss
      to be applied to wedig.xml to create XHTML slides
      using James Clark's XT

      Usage:  xt wedig.xml wedig.xsl

      Normally, you would have a third file on the command line, but
      in this case all the output files are created by xt:document ...
-->

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xt="http://www.jclark.com/xt"
                extension-element-prefixes="xt"
                >
<!--
      Note: there is a bug in the current version of XT (Nov. '99):
      One should be able to put xmlns="http://http://www.w3.org/1999/xhtml"
      up with all the other namespaces, so that the root element is

        <html xmlns="http://http://www.w3.org/1999/xhtml">

      on output.  Well, that part works, but it then adds stuff like

        <p xmlns="">

      (emtpy namespaces on elements directly under body).  So, you
      have to leave out the namespace declaration.  That's OK, the
      pages still validate.  Namespaces are a pain anyway.

      BUT - that namespace is supposedly required for XHTML!  See:
      http://www.w3.org/TR/xhtml1/#docconf

      Note that an output namespace does not apply to old-style HTML.
-->

<xsl:output method="xml" indent="yes"
     omit-xml-declaration="yes"
     doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
     doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />

<xsl:template match="/">
     <xsl:apply-templates select="//page" />  <!-- pages anywhere -->
</xsl:template>

<xsl:template match="page">

    <!-- first define some variables -->
    <xsl:variable name="pagenumber">
      <xsl:value-of select="position()"/>
    </xsl:variable>

    <xsl:variable name="pagename">
      <xsl:choose>
        <xsl:when test="position() = 1">index.html</xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="concat('page',$pagenumber,'.html')"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="prevpage">
       <xsl:choose>
        <xsl:when test="position() = 2">index.html</xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="concat('page',$pagenumber -1,'.html')"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="nextpage">
      <xsl:value-of select="concat('page',$pagenumber + 1,'.html')"/>
    </xsl:variable>
    <!-- done with variables -->

    <!-- now use XT's extensions to create the XHTML files -->
    <xt:document method="xml" href="{$pagename}">

    <!-- OK, here we go -->
    <html>
    <head>
	    <title><xsl:value-of select="@title"/></title>
<!--
      <meta content="blendTrans(Duration=3)" http-equiv="Page-Enter" />
-->
      <link rel="stylesheet" type="text/css" href="slides.css" />
    </head>
    <body>
        <!-- double click to get to next next page - what the heck -->
        <xsl:if test="following::page">
          <xsl:attribute name="ondblclick">location.href='<xsl:value-of select="$nextpage" />'</xsl:attribute>
        </xsl:if>

        <!-- header -->
        <xsl:if test="preceding::page"> <!-- don't show on 1st page -->
          <p class="header">
            <xsl:if test="preceding::page">
              <a href="{$prevpage}">previous</a> | <a href="index.html">start</a>
              <xsl:if test="position() != last()"> | </xsl:if>
            </xsl:if>
            <xsl:if test="following::page">
              <a href="{$nextpage}">next</a>
            </xsl:if>
          </p>
          <hr/>
        </xsl:if>
        <!-- end header -->

        <h1><xsl:value-of select="@title"/></h1>

        <xsl:apply-templates/> <!-- now do the body stuff -->

        <!-- footer -->
        <hr/>
        <p class="footer">
          <xsl:if test="preceding::page">
            <a href="{$prevpage}">previous</a> | <a href="index.html">start</a>
            <xsl:if test="position() != last()"> | </xsl:if>
          </xsl:if>
          <xsl:if test="following::page">
            <a href="{$nextpage}">next</a>
          </xsl:if>
        </p>
        <!-- end footer -->

    </body>
    </html>
   </xt:document>
</xsl:template>

<xsl:template match="*|@*"> <!-- copies all the HTML straight through -->
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:apply-templates select="node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
