<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:saxon="http://icl.com/saxon"
                extension-element-prefixes="saxon"
                xmlns:xinclude="http://www.w3.org/2001/XInclude"
                exclude-result-prefixes="xinclude">

  <xsl:output method="xml" indent="no" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.cafeconleche.org/DTD/xhtml1-transitional.dtd"/>

  <xsl:variable name="date"><xsl:value-of select="/presentation/date"/></xsl:variable>
  <xsl:variable name="host"><xsl:value-of select="/presentation/host"/></xsl:variable>

  <xsl:template match="/presentation">
     <xsl:document method="xml" indent="no" 
                   doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.cafeconleche.org/DTD/xhtml1-transitional.dtd" encoding="UTF-8" href="index.html">
       <html lang="en-US" xml:lang="en-US">
         <head>
            <link rel="stylesheet"   href="onscreen.css" type="text/css" media="screen, projection" />
           <meta http-equiv="Content-Style-Type" content="text/css" />
           <meta name="description" 
                 content="{abstract}"></meta>
           <title><xsl:value-of select="title"/></title>         
         </head>
         <body> 
           <h1 class="title"><xsl:value-of select="title"/></h1> 
           <ul>
             <xsl:for-each select="slide">
               <li><a href="{format-number(position(),'00')}.html"><xsl:value-of select="title"/></a></li>
             </xsl:for-each>    
           </ul>           
           
           <p><a href="{translate(translate(title,' ', '_'), ':', '_')}.html">Entire Presentation as Single File</a></p>
              
           <hr/>
           <div class="navigation">
             <a href="01.html">Start</a> | <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
           </div>
           <hr/>
           <div class="footer">
              Copyright <xsl:value-of select="/presentation/copyright"/> <br/>
              Last Modified <xsl:apply-templates select="last_modified" mode="lm"/>
           </div>
         </body>     
       </html>     
     </xsl:document>     

     <!-- Onscreen Index -->
     <xsl:document method="xml" indent="no" 
                   doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.cafeconleche.org/DTD/xhtml1-transitional.dtd" encoding="UTF-8" href="onscreenindex.html">
       <html lang="en-US" xml:lang="en-US">
         <head>
            <link rel="stylesheet"   href="onscreen.css" type="text/css" media="screen, projection" />
           <meta name="description" 
                 content="{abstract}"></meta>
           <title><xsl:value-of select="title"/></title>         
         </head>
         <body> 
           <h1 class="title"><xsl:value-of select="title"/></h1> 
           <ul>
             <xsl:for-each select="slide">
               <li><a href="onscreen{format-number(position(),'00')}.html"><xsl:value-of select="title"/></a></li>
             </xsl:for-each>    
           </ul>           
           
           <p><a href="{translate(translate(title,' ', '_'), ':', '_')}.html">Entire Presentation as Single File</a></p>
              
           <hr/>
           <div class="navigation">
             <a href="onscreen01.html">Start</a> | <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
           </div>
           <hr/>
           <div class="footer">
              Copyright <xsl:value-of select="/presentation/copyright"/><br/>       
              <a href="mailto:{/presentation/author_email}"><xsl:value-of select="/presentation/author_email"/></a><br/>
              Last Modified <xsl:apply-templates select="last_modified" mode="lm"/>
           </div>
         </body>     
       </html>     
     </xsl:document> 
     
     <!-- single file output -->
     <xsl:document method="xml" encoding="UTF-8" href="{translate(translate(title,' ', '_'), ':', '_')}.html">
       <html lang="en-US" xml:lang="en-US">
         <head>
            <link rel="stylesheet"   href="onscreen.css" type="text/css" media="screen, projection" />
           <meta name="description" 
                 content="{abstract}"></meta>
           <title><xsl:value-of select="title"/></title>
         </head>
         <body>
             <xsl:for-each select="slide">
               <xsl:if test="not(@print='false')">
                 <h2><xsl:value-of select="title"/></h2>
                 <xsl:apply-templates select="*[name()!='title']"/>
                 <hr color="red" style="color: red" size="2"/>
               </xsl:if>
             </xsl:for-each>    
           <div class="navigation">
             <a href="index.html">Index</a> | <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
           </div>
           <hr/>
           <div class="footer">
              Copyright <xsl:value-of select="/presentation/copyright"/><br/>       
              <a href="mailto:{/presentation/author_email}"><xsl:value-of select="/presentation/author_email"/></a><br/>
              Last Modified <xsl:apply-templates select="last_modified" mode="lm"/>
           </div>
         </body>     
       </html>     
     </xsl:document>  

     <xsl:apply-templates select="slide"/>

  </xsl:template>
 
  
  <xsl:template match="slide">
  
     <!-- For online use default styles --> 
     <xsl:document method="xml" 
     doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 
     doctype-system="http://www.cafeconleche.org/DTD/xhtml1-transitional.dtd" 
     encoding="UTF-8"
     href="{format-number(position(),'00')}.html">
       <html lang="en-US" xml:lang="en-US">
         <head>
            <link rel="stylesheet" href="screen.css" type="text/css" media="screen, projection" />
           <meta http-equiv="Content-Style-Type" content="text/css" />
           <meta name="description">
             <xsl:attribute name="content">
               <xsl:apply-templates select="description" mode="meta"/>
             </xsl:attribute>
           </meta>
           <title><xsl:value-of select="title"/></title>
           <script type="text/javascript"> 
             <xsl:comment>
              var isnav
              
              if (parseInt(navigator.appVersion) >= 4) {
                if (navigator.appName == "Netscape") {
                  isNav = true
                  document.captureEvents(Event.KEYPRESS)
                }
                else {
                  isNav = false
                }
              }
              document.onkeypress = flipslide

              function flipslide(evt) {
                var key = isNav ? evt.which : window.event.keyCode
                if (key == 32 || key == 29 || key == 30 || key == 11) {
                  <xsl:if test="position()!=last()">
                    location.href="<xsl:number value="position()+1" format="01"/>.html"
                  </xsl:if>
                }
                else if (key == 28 || key == 31 || key == 12) {
                  <xsl:if test="position()!=1">
                    location.href="<xsl:number value="position()-1" format="01"/>.html"
                  </xsl:if>
                  <xsl:if test="position()=1">
                    location.href="index.html"
                  </xsl:if>
                }
                else if (key == 1) {
                  location.href="index.html";
                }
              } // </xsl:comment>             
           </script>         
         </head>
         <body>           
             <xsl:apply-templates/>                  
           <hr/>
           <!-- Need to treat first and last slide specially --> 
           <xsl:choose>
             <xsl:when test="position()=1">
               <div class="navigation">
                 <a href="{format-number(position()+1,'00')}.html">Next</a> 
                 | <a href="index.html">Top</a> 
                 | <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
               </div>
             </xsl:when>
             <xsl:when test="position()=last()">
               <div class="navigation">
                 <a href="01.html">Start</a> 
                 | <a href="{format-number(position()-1,'00')}.html">Previous</a> 
                 | <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
               </div>
             </xsl:when>
             <xsl:otherwise>
               <div class="navigation">
                 <a href="{format-number(position()-1,'00')}.html">Previous</a> 
                 | <a href="{format-number(position()+1,'00')}.html">Next</a> 
                 | <a href="index.html">Top</a> 
                 | <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
               </div>
             </xsl:otherwise>
           </xsl:choose>

           <hr/>
           <div class="footer">
              Copyright <xsl:value-of select="/presentation/copyright"/> <br/>       
              <a href="mailto:{/presentation/author_email}"><xsl:value-of select="/presentation/author_email"/></a><br/>
              Last Modified 
              <xsl:choose>
                <xsl:when test="last_modified">
                  <xsl:value-of select="last_modified"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="/presentation/default_last_modified"/>
                </xsl:otherwise>
              </xsl:choose>
           </div>
         </body>     
       </html>
     </xsl:document>
     
    <!-- For onscreen presentation, use larger fonts with navigation --> 
    <xsl:document method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.cafeconleche.org/DTD/xhtml1-transitional.dtd"  encoding="UTF-8" href="onscreen{format-number(position(),'00')}.html">
       <html lang="en-US" xml:lang="en-US">
         <head>
            <link rel="stylesheet" href="onscreen.css" type="text/css" media="screen, projection" />
           <meta name="description">
             <xsl:attribute name="content">
               <xsl:apply-templates select="description" mode="meta" />
             </xsl:attribute>
           </meta>
           
           <title><xsl:value-of select="title"/></title>         
           <script type="text/javascript"> 
              <xsl:comment>
              var isnav
              
              if (parseInt(navigator.appVersion) >= 4) {
                if (navigator.appName == "Netscape") {
                  isNav = true
                  document.captureEvents(Event.KEYPRESS)
                }
                else {
                  isNav = false
                }
              }
              document.onkeypress = flipslide

              function flipslide(evt) {
                var key = isNav ? evt.which : window.event.keyCode
                if (key == 32 || key == 29 || key == 30 || key == 11) {
                  <xsl:if test="position()!=last()">
                    location.href="onscreen<xsl:number value="position()+1" format="01"/>.html"
                  </xsl:if>
                }
                else if (key == 28 || key == 31 || key == 12) {
                  <xsl:if test="position()!=1">
                    location.href="onscreen<xsl:number value="position()-1" format="01"/>.html"
                  </xsl:if>
                  <xsl:if test="position()=1">
                    location.href="index.html"
                  </xsl:if>
                }
                else if (key == 1) {
                  location.href="index.html";
                }
              } // </xsl:comment>             
           </script> 
         </head>
         <body>           
             <xsl:apply-templates/>
           <hr/>                  
           <!-- Need to treat first and last slide specially --> 
           <xsl:choose>
             <xsl:when test="position()=1">
               <div class="navigation">
                 <a href="onscreen{format-number(position()+1,'00')}.html">Next</a>
                  | <a href="onscreenindex.html">Top</a> | <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
               </div>
             </xsl:when>
             <xsl:when test="position()=last()">
               <div class="navigation">
                 <a href="onscreen01.html">Start</a> 
                 | <a href="onscreen{format-number(position()-1,'00')}.html">Previous</a> 
                  | <a href="onscreenindex.html">Top</a> |
                 <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
               </div>
             </xsl:when>
             <xsl:otherwise>
               <div class="navigation">
                 <a href="onscreen{format-number(position()-1,'00')}.html">Previous</a> 
                 | <a href="onscreen{format-number(position()+1,'00')}.html">Next</a>
                 | <a href="onscreenindex.html">Top</a> 
                 | <a href="http://www.cafeconleche.org/">Cafe con Leche</a>
               </div>
             </xsl:otherwise>
           </xsl:choose>

           <hr/>
           <div class="footer">
              Copyright <xsl:value-of select="/presentation/copyright"/> <br/>       
              <a href="mailto:{/presentation/author_email}"><xsl:value-of select="/presentation/author_email"/></a><br/>
              Last Modified 
              <xsl:choose>
                <xsl:when test="last_modified">
                  <xsl:value-of select="last_modified"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="/presentation/default_last_modified"/>
                </xsl:otherwise>
              </xsl:choose>
           </div>
         </body>     
       </html>
     </xsl:document>
      
  </xsl:template>
    
  <xsl:template match="title">  
    <h1 class="title"><xsl:value-of select="."/></h1>
  </xsl:template>  
  
  <xsl:template match="description"/>    
    
  
  <xsl:template match="last_modified"/>    

  <xsl:template match="last_modified" mode="lm">  
    <xsl:value-of select="."/>
  </xsl:template>  
  
  <xsl:template match="default_last_modified">  
    <xsl:value-of select="."/>
  </xsl:template>  
  
  <xsl:template match="date_ref" mode="meta"><xsl:value-of select="$date"/></xsl:template>  
  <xsl:template match="host_ref" mode="meta"><xsl:value-of select="$host"/></xsl:template>  
  
  <xsl:template match="date_ref">  
    <xsl:value-of select="/presentation/date"/>
  </xsl:template>  
  
  <xsl:template match="host_ref">  
    <xsl:value-of select="/presentation/host"/>
  </xsl:template>  
  
  <xsl:template match="li">  
    <li><p><xsl:apply-templates/></p></li>
  </xsl:template>  
  
  <!-- Ignore contents of notes when printing slides -->    
  <xsl:template match="note"/>  

  <!-- pass HTML along with new namespace -->
  <xsl:template match="*">
    <xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
      <xsl:apply-templates select="@*|*|text()"/>
    </xsl:element>
  </xsl:template>      
  
  <xsl:template match="@*">
    <xsl:copy>
      <xsl:apply-templates select="*|@*|text()"/>
    </xsl:copy>
  </xsl:template>


</xsl:stylesheet>
