<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:h="http://www.w3.org/1999/xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                exclude-result-prefixes="h"
                version="1.0">

  <!-- file extension for generated slides -->
  <xsl:param name="ext" select="'html'"/>

  <!-- whether to include notes in slides or not -->
  <xsl:param name="display-notes" select="'yes'"/>

  <!-- whether to include the source's CSS or not -->
  <xsl:param name="include-source-css-p" select="false()"/>

  <!-- where the w3c stylesheets are -->
  <xsl:param name="w3c-css" select="'.'"/>
  <!--  <xsl:param name="w3c-css" select="http://www.w3.org/Talks/Tools/"/> -->

  <!-- where the w3c icons are -->
  <xsl:param name="w3c-icons" select="'.'"/>
  <xsl:param name="w3c-talks-icons" select="'.'"/>
  <!--  <xsl:param name="w3c-css" select="http://www.w3.org/Talks/Tools/"/> -->

  <!-- CSS stylesheets to use in slides -->
  <xsl:param name="w3c-ss">
    <link href="{$w3c-css}/w3ctalk-640w.css" rel="stylesheet" type="text/css" title="640w"/>
    <link href="{$w3c-css}/w3ctalk-640.css" rel="alternate stylesheet" type="text/css" title="640"/>
    <link href="{$w3c-css}/w3ctalk-800w.css" rel="alternate stylesheet" type="text/css" title="800w"/>
    <link href="{$w3c-css}/w3ctalk-800.css" rel="alternate stylesheet" type="text/css" title="800"/>
    <link href="{$w3c-css}/w3ctalk-1024w.css" rel="alternate stylesheet" type="text/css" title="1024w"/>
    <link href="{$w3c-css}/w3ctalk-1024.css" rel="alternate stylesheet" type="text/css" title="1024"/>
  </xsl:param>


  <xsl:output method="xhtml" indent="yes"/>
    <!--
    doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
    doctype-system="http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd"
-->

  <xsl:variable name="authors" select="/h:html/h:head/h:meta[@name='author']/@content"/>

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

  <xsl:template match="h:html">
    <xsl:apply-templates select="h:body"/>
  </xsl:template>


  <xsl:template match="h:body">

    <!-- first slide: ToC -->

    <xsl:copy-of select="/processing-instruction()"/>

    <html>
      <head>
        <title><xsl:value-of select="h:h1"/> - Slide List</title>
        <!-- copy stylesheets used in all.xhtml -->
        <xsl:if test="$include-source-css-p">
          <xsl:copy-of select="/h:html/h:head/h:link"/>
          <xsl:copy-of select="/h:html/h:head/h:style"/>
        </xsl:if>
        <xsl:copy-of select="$w3c-ss"/>
      </head>
      <body>
        <table class="navbar" width="97%" summary="header logo">
          <tr valign="top">
            <td><a href="http://www.w3.org/"><img src="{$w3c-icons}/w3c_home.gif" alt="W3C "/></a></td>
          </tr>
        </table>
        <h1><xsl:value-of select="h:h1"/></h1>
        <p>by <xsl:value-of select="$authors" separator=", "/></p>
        <h2>Table of Contents</h2>
        <ul>
          <xsl:for-each select="h:h2">
            <li><a accesskey="1" tabindex="1" href="slide{count(preceding-sibling::h:h2)+1}.{$ext}"><xsl:apply-templates/></a></li>
          </xsl:for-each>
        </ul>
      </body>
    </html>

    <xsl:for-each-group select="*" group-starting-with="h:h2">
      <xsl:if test="self::h:h2">
        <xsl:variable name="slide-number" select="count(preceding-sibling::h:h2)+1"/>
        <xsl:message><xsl:value-of select="$slide-number"/>: <xsl:value-of select="self::h:h2"/></xsl:message>

        <xsl:variable name="previous">
          <a rel="previous" href="{if ($slide-number = 1) then concat('Overview.',$ext) else concat('slide',$slide-number - 1,'.',$ext)}" accesskey="P">
            <img src="{$w3c-talks-icons}/left.gif" width="32" height="32" alt=" previous" title="Back to &#34;{preceding::h:h2[1]}&#34;"/>
          </a>
        </xsl:variable>

        <xsl:variable name="next">
          <a rel="next" href="{if (count(following-sibling::h:h2)=0) then concat('Overview.',$ext) else concat('slide',$slide-number +1,'.',$ext)}" accesskey="N">
            <img src="{$w3c-talks-icons}/right.gif" width="32" height="32" alt=" next" title="On to &#34;{following::h:h2[1]}&#34;"/>
          </a>            
        </xsl:variable>

        
        <xsl:result-document href="slide{$slide-number}.{$ext}">
          <xsl:copy-of select="/processing-instruction()"/>

          <html>
            <head>
              <title><xsl:value-of select="self::h:h2"/></title>
              <xsl:if test="$include-source-css-p">
                <xsl:copy-of select="/h:html/h:head/h:link"/>
                <xsl:copy-of select="/h:html/h:head/h:style"/>
              </xsl:if>
              <xsl:copy-of select="$w3c-ss"/>
            </head>
            <body>
              <a href="http://www.w3.org/"><img src="{$w3c-icons}/w3c_home.gif" alt="W3C  "/></a>
              <h1 class="slide"><xsl:copy-of select="current-group()[self::h:h2]"/></h1>
              <hr class="top"/>
              <div>
                <xsl:for-each select="current-group()[not(self::h:h2)]">
                  <xsl:apply-templates select="."/>
                </xsl:for-each> 
              </div>

              <hr class="bottom"/>

              <table class="navbar" cellspacing="0" cellpadding="0" width="97%" summary="footer">
                <tr valign="bottom">
                  <td><p class="author"><xsl:value-of select="$authors" separator=", "/></p></td>
                  <td><p class="index"><xsl:value-of select="$slide-number"/> of <xsl:value-of select="count(/h:html/h:body/h:h2)"/></p></td>
<td valign="top">
<div>
  <xsl:copy-of select="$previous"/>
  <a rel="contents" href="Overview.{$ext}" accesskey="C">
    <img src="{$w3c-talks-icons}/toc.png" width="32" height="32" alt=" contents" title="Table of Contents"/>
  </a>
  <xsl:copy-of select="$next"/>
</div>
</td>

</tr>
</table>

            </body>
          </html>
        </xsl:result-document>
      </xsl:if>
    </xsl:for-each-group>
  </xsl:template>

<!-- ###################################################################### -->

<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

  <xsl:template match="h:div[@class='comment']">
    <xsl:if test="$display-notes='yes'">
      <div class="note">
        <xsl:text>[</xsl:text>
        <xsl:apply-templates/>
      <xsl:text>]</xsl:text>
    </div>
  </xsl:if>
  </xsl:template>
</xsl:stylesheet>
