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

  <xsl:output method="xml"
    indent="yes"
    doctype-system="slideshow.dtd" />
  
  <xsl:template match="/xhtml:html">
    <slideshow>
      <xsl:apply-templates select="xhtml:head" />
      <xsl:apply-templates select="xhtml:body/xhtml:div[@class='layout']" />
      <xsl:apply-templates select="xhtml:body/xhtml:div[@class='presentation']" />
    </slideshow>
  </xsl:template>

  <xsl:template match="xhtml:head">
    <metadata>
      
      <title>
        <xsl:value-of select="xhtml:title" />
      </title>

      <xsl:apply-templates select="xhtml:meta[@name='version']" />
      <xsl:apply-templates select="xhtml:meta[@name='generator']" />
      <xsl:apply-templates select="xhtml:meta[@name='presdate']" />
      <xsl:apply-templates select="xhtml:meta[@name='author']" />
      <xsl:apply-templates select="xhtml:meta[@name='company']" />
      <xsl:apply-templates select="xhtml:meta[@name='defaultView']" />
      <xsl:apply-templates select="xhtml:meta[@name='controlVis']" />
    </metadata>
  </xsl:template>

  <xsl:template match="xhtml:meta[@name='version']">
    <version>
      <xsl:value-of select="@content" />
    </version>
  </xsl:template>

  <xsl:template match="xhtml:meta[@name='generator']">
    <generator>
      <xsl:value-of select="@content" />
    </generator>
  </xsl:template>

  <xsl:template match="xhtml:meta[@name='presdate']">
    <presdate>
      <xsl:value-of select="@content" />
    </presdate>
  </xsl:template>

  <xsl:template match="xhtml:meta[@name='author']">
    <author>
      <xsl:value-of select="@content" />
    </author>
  </xsl:template>

  <xsl:template match="xhtml:meta[@name='company']">
    <company>
      <xsl:value-of select="@content" />
    </company>
  </xsl:template>

  <xsl:template match="xhtml:meta[@name='http-equiv']">
    <http-equiv>
      <xsl:value-of select="@content" />
    </http-equiv>
  </xsl:template>

  <xsl:template match="xhtml:meta[@name='defaultView']">
    <defaultView>
      <xsl:attribute name="content">
        <xsl:value-of select="@content" />
      </xsl:attribute>
    </defaultView>
  </xsl:template>

  <xsl:template match="xhtml:meta[@name='controlVis']">
    <controlVis>
      <xsl:attribute name="content">
        <xsl:value-of select="@content" />
      </xsl:attribute>
    </controlVis>
  </xsl:template>

  <xsl:template match="xhtml:div[@class='layout']" >
    <layout>
      <header><xsl:apply-templates select="xhtml:div[@id='header']" /></header>
      <footer><xsl:apply-templates select="xhtml:div[@id='footer']" /></footer>
      <!-- need to add the optional elements topleft etc-->
    </layout>
  </xsl:template>

  <xsl:template match="xhtml:div[@id='header']">
    <xsl:apply-templates mode="copy" />
  </xsl:template>

 <xsl:template match="xhtml:div[@id='footer']">
   <xsl:apply-templates mode="copy" />
 </xsl:template>


 <xsl:template match="xhtml:div[@class='presentation']">
   <presentation>
     <xsl:apply-templates select="xhtml:div[@class='slide']" />
   </presentation>
 </xsl:template>

 <xsl:template match="xhtml:div[@class='slide']" >
   <slide>
     <xsl:apply-templates mode="copy"  />
   </slide>
 </xsl:template>

 <xsl:template match="xhtml:div[@class='slide']/xhtml:h1">
   <title><xsl:value-of select="." /></title>
 </xsl:template>

 <xsl:template match="xhtml:div[@class='slidecontent']">
   <slidecontent>
     <xsl:apply-templates mode="copy" />
   </slidecontent>
 </xsl:template>

 <xsl:template match="xhtml:div[@class='handout']">
   <slidecontent>
     <xsl:apply-templates mode="copy" />
   </slidecontent>
 </xsl:template>


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

</xsl:stylesheet>
