html.xsl
branchstyles
changeset 0 08de8d15f932
child 3 6e7e05c2ded6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/html.xsl	Tue Dec 27 13:55:27 2005 -0500
@@ -0,0 +1,436 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.1"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xt="http://www.jclark.com/xt"
+  xmlns="http://www.w3.org/1999/xhtml"
+  extension-element-prefixes="xt">
+
+<xsl:import href="common.xsl"/>
+
+  <xsl:output method="xml"
+	encoding="utf-8"
+        doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
+        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
+        indent="yes"/>
+
+<xsl:param name="css-base-dir"/>
+<xsl:param name="stylesheet"><xsl:text>html.xsl</xsl:text></xsl:param>
+<xsl:param name="pdf-filename"><xsl:text>book.pdf</xsl:text></xsl:param>
+
+<xsl:template name="get-id">    
+  <xsl:choose>
+    <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when>
+    <xsl:otherwise><xsl:value-of select="generate-id(.)"/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+<xsl:template name="parent-id">
+  <xsl:choose>
+    <xsl:when test="../@id"><xsl:value-of select="../@id"/></xsl:when>
+    <xsl:otherwise><xsl:value-of select="generate-id(..)"/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+<xsl:template name="next-id">
+  <xsl:choose>
+    <xsl:when test="following::*[1]/@id"><xsl:value-of select="following::*[1]/@id"/></xsl:when>
+    <xsl:otherwise><xsl:value-of select="generate-id(following::*[1])"/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+<xsl:template name="prec-id">
+  <xsl:choose>
+    <xsl:when test="preceding::*[1]/@id"><xsl:value-of select="preceding::*[1]/@id"/></xsl:when>
+    <xsl:otherwise><xsl:value-of select="generate-id(preceding::*[1])"/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- book processing -->
+<xsl:template match="book">
+  <html>
+    <head>
+      <xsl:choose>
+        <xsl:when test="docinfo">
+           <xsl:apply-templates select="docinfo" mode="heading"/> 
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:apply-templates select="title" mode="heading"/>
+        </xsl:otherwise>
+      </xsl:choose>
+      <link href="{$css-base-dir}{$stylesheet}" media="screen" rel="stylesheet" type="text/css"/>
+    </head>
+    <body class="book">
+      <xsl:apply-templates select="docinfo/date"/>
+      <xsl:apply-templates/>
+      <xsl:apply-templates mode="book-toc"/>
+      <hr/>
+      <address>
+        <xsl:apply-templates select="docinfo/copyright"/>
+	<p>Aussi disponible au format <a href="{$pdf-filename}">PDF</a>.</p>
+      </address>
+    </body>
+  </html>
+</xsl:template>
+
+<xsl:template match="book/section" mode="book-toc">
+  <xsl:variable name="href">
+    <xsl:call-template name="get-id"/>
+  </xsl:variable>
+  <h2>
+    <a id="{$href}" href="{$href}.html">
+      <xsl:apply-templates select="title" mode="book-toc"/>
+    </a>
+  </h2>
+</xsl:template>
+
+<!-- title default processing -->
+<xsl:template match="title">
+  <h1><xsl:apply-templates/></h1>
+</xsl:template>
+<xsl:template match="subtitle">
+  <p class="subtitle"><em><xsl:apply-templates/></em></p>
+</xsl:template>
+
+<!-- normal name processing -->
+<xsl:template name="name">
+  <xsl:variable name="fullname">
+     <xsl:apply-templates select="firstname"/>
+     <xsl:if test="initials">
+       <xsl:text> </xsl:text>
+       <xsl:apply-templates select="initials"/>
+     </xsl:if>
+     <xsl:text> </xsl:text>
+     <xsl:apply-templates select="surname"/>    
+  </xsl:variable>
+  <xsl:choose>
+  <xsl:when test="email">
+    <a href="mailto:{email/text()}" class="mailto">
+      <xsl:value-of select="$fullname"/>
+    </a>
+  </xsl:when>
+  <xsl:otherwise>
+    <xsl:value-of select="$fullname"/>
+  </xsl:otherwise>
+  </xsl:choose>           
+</xsl:template>
+
+<xsl:template match="*" mode="fullname">
+  <xsl:call-template name="name"/>  
+</xsl:template>
+<xsl:template match="email">
+  <a href="mailto:{.}"><xsl:value-of select="."/></a>
+</xsl:template>
+<xsl:template match="web">
+  <a href="{.}"><xsl:value-of select="."/></a>
+</xsl:template>
+<!-- simple address format, good for Canada -->
+<xsl:template match="address">
+  <xsl:apply-templates mode="address" select="street"/>
+  <xsl:value-of select="city"/>
+  (<xsl:value-of select="state"/>),
+  <xsl:value-of select="postcode"/><br/>
+  <xsl:apply-templates select="country" mode="address"/>    
+</xsl:template>
+<xsl:template match="*" mode="address">
+  <xsl:apply-templates/><br/>
+</xsl:template>
+
+<!-- default docinfo processing -->
+<!-- normal is not process -->
+<xsl:template match="docinfo"/>
+<!-- date processing if directly selected -->
+<xsl:template match="date">
+  <address class="date">
+    <xsl:apply-templates/>
+  </address>
+</xsl:template>
+<!-- in heading, default is to not process. -->
+<xsl:template match="*" mode="heading"/>
+<xsl:template match="docinfo" mode="heading">
+  <xsl:apply-templates mode="heading"/>
+</xsl:template>
+<xsl:template match="title" mode="heading">
+  <title><xsl:apply-templates/></title>
+</xsl:template>
+<xsl:template match="author" mode="heading">
+  <meta name="author">
+    <xsl:attribute name="content">
+      <xsl:if test="firstname">
+        <xsl:apply-templates select="firstname"/><xsl:text> </xsl:text>
+      </xsl:if>
+      <xsl:if test="initials">
+        <xsl:apply-templates select="initials"/><xsl:text> </xsl:text>
+      </xsl:if>
+      <xsl:apply-templates select="surname"/>
+    </xsl:attribute>
+  </meta>
+</xsl:template>
+<xsl:template match="date" mode="heading">
+  <meta name="date" content="{text()}"/>
+</xsl:template>
+
+<!-- copyright footer processing -->
+<xsl:template match="copyright">
+  © <xsl:apply-templates select="holder"/>
+  <xsl:text> </xsl:text>
+  <xsl:apply-templates select="year"/>
+</xsl:template>
+<xsl:template match="holder">
+  <xsl:call-template name="name"/>
+</xsl:template>
+<xsl:template match="year">
+  <xsl:apply-templates/>
+  <xsl:if test="position() != last()">
+    <xsl:text>, </xsl:text>
+  </xsl:if>
+</xsl:template>
+
+<!-- nda docinfo processing -->
+<xsl:template match="*" mode="heading-nda"/>
+<xsl:template match="title" mode="heading-nda">
+  <title>
+    <xsl:apply-templates/><xsl:text> (Notes de l'auteur)</xsl:text>
+  </title>
+</xsl:template>
+<xsl:template match="docinfo" mode="heading-nda">
+  <xsl:apply-templates mode="heading-nda"/>
+  <xsl:apply-templates select='*[name()!="title"]' mode="heading"/> 
+</xsl:template>
+
+<!-- para default processing -->
+<xsl:template match="para">
+  <p><xsl:apply-templates/></p>
+</xsl:template>
+
+<!-- formalpara processing -->
+<xsl:template match="formalpara/para">
+  <xsl:apply-templates/>
+</xsl:template>
+<xsl:template match="formalpara/title">
+  <strong><xsl:apply-templates/></strong>
+</xsl:template>
+<xsl:template match="formalpara">
+  <p><xsl:apply-templates/></p>
+</xsl:template>
+
+<!-- citation -->
+<xsl:template match="citation/author">
+  <address><xsl:apply-templates/></address>
+</xsl:template>
+<xsl:template match="citation">
+  <blockquote><xsl:apply-templates/></blockquote>
+</xsl:template>
+<xsl:template match="author/surname">
+  <xsl:apply-templates/>
+  <xsl:if test="following-sibling::author">
+    <xsl:text>, </xsl:text>
+  </xsl:if>
+</xsl:template>
+<xsl:template match="author/title">
+  <xsl:apply-templates/>
+</xsl:template>
+
+<!-- list processing -->
+<xsl:template match="list">
+  <xsl:choose>
+    <xsl:when test="@type='none'">
+      <ul>
+        <xsl:apply-templates/>
+      </ul>
+    </xsl:when>
+    <xsl:otherwise>
+      <ol type="{@id}">
+        <xsl:apply-templates/>
+      </ol>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+<xsl:template match="shortlist">
+  <p><xsl:apply-templates mode="short"/></p>
+</xsl:template>
+
+<xsl:template match="item|listitem">
+  <li><xsl:apply-templates/></li>
+</xsl:template>
+
+<!-- inline element -->
+<xsl:template match="emphasis">
+  <em><xsl:apply-templates/></em>
+</xsl:template>
+<xsl:template match="term">
+  <em class="term"><xsl:apply-templates/></em>
+</xsl:template>
+<xsl:template match="foreign">
+  <em class="foreign"><xsl:apply-templates/></em>
+</xsl:template>
+<xsl:template match="replaceable">
+  <em class="replaceable">
+    <xsl:text>[</xsl:text>
+    <xsl:apply-templates/>
+    <xsl:text>]</xsl:text>
+  </em>
+</xsl:template>
+<xsl:template match="literal">
+  <tt class="literal"><xsl:apply-templates/></tt>
+</xsl:template>
+<xsl:template match="acronym[@text]">
+  <acronym title="{@text}"><xsl:apply-templates/></acronym>
+</xsl:template>
+<xsl:template match="acronym">
+  <acronym><xsl:apply-templates/></acronym>
+</xsl:template>
+
+<xsl:template match="subscript">
+  <sub><xsl:apply-templates/></sub>
+</xsl:template>
+<xsl:template match="superscript">
+  <sup><xsl:apply-templates/></sup>
+</xsl:template>
+
+<xsl:template match="section" mode="navbar-name">
+  <xsl:value-of select="title/text()"/>
+</xsl:template>
+
+<xsl:template match="section|story|poetry" mode="navbar-link">
+  <xsl:call-template name="get-id"/>
+</xsl:template>
+
+<xsl:template name="navbar-link">
+  <xsl:param name="prefix"></xsl:param>
+  <a>
+    <xsl:attribute name="href">
+      <xsl:apply-templates select="." mode="navbar-link"/>
+      <xsl:text>.html</xsl:text>
+    </xsl:attribute>
+    <xsl:value-of select="$prefix"/>
+    <xsl:apply-templates select="." mode="navbar-name"/>
+  </a><br/>
+</xsl:template>
+
+<xsl:template match="section" mode="navbar-prec">
+  <xsl:call-template name="navbar-link">
+    <xsl:with-param name="prefix">
+      <xsl:text>Section précédente: </xsl:text>
+    </xsl:with-param>
+  </xsl:call-template>
+</xsl:template>
+<xsl:template match="section" mode="navbar-next">
+  <xsl:call-template name="navbar-link">
+    <xsl:with-param name="prefix">
+      <xsl:text>Section suivante: </xsl:text>
+    </xsl:with-param>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="section" mode="navbar-section">
+   <xsl:apply-templates 
+     select="preceding-sibling::section[1]"
+     mode="navbar-prec"/>
+   <xsl:apply-templates 
+     select="following-sibling::section[1]"
+     mode="navbar-next"/>
+  <xsl:variable name="section-ref">
+    <xsl:call-template name="get-id"/>
+  </xsl:variable>
+  <a href="index.html#{$section-ref}">Retour à la table des matières</a><br/>
+</xsl:template>
+
+<!-- The book-toc section -->
+<xsl:template match="book/section">
+  <xsl:variable name="href">
+    <xsl:call-template name="get-id"/>
+  </xsl:variable>
+  <xt:document href="{$href}.html" method="xml" encoding="utf-8"
+        doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
+        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
+        indent="yes">
+    <html>
+      <head>
+        <xsl:apply-templates select="title" mode="heading"/>
+        <link href="{$css-base-dir}{$stylesheet}" media="screen" rel="stylesheet" type="text/css"/>
+      </head>
+      <body>
+        <h1><xsl:value-of select="title"/></h1>
+        <xsl:apply-templates select="child::*[name(.) != 'story' or name(.)!= 'poetry']"/>
+        <ul>
+          <xsl:apply-templates mode="section-toc"/>
+        </ul>
+        <hr/>
+        <address>
+          <xsl:apply-templates select="../copyright"/>
+        </address>
+        <xsl:apply-templates mode="navbar-section" select="."/>
+      </body>
+    </html>
+  </xt:document>
+  <xsl:apply-templates select="story|poetry"/>
+</xsl:template>
+
+<xsl:template match="section/title" mode="book-toc">
+  <xsl:apply-templates/>
+</xsl:template>
+
+<!-- anything else is clear -->
+<xsl:template match="*" mode="book-toc"/>
+<xsl:template match="*" mode="section-toc"/>
+<xsl:template match="*" mode="navbar-section"/>
+
+<!-- preambule section -->
+<xsl:template match="preambule">
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="preambule/title">
+  <h2><xsl:apply-templates/></h2>
+</xsl:template>
+
+<!-- short representation -->
+<xsl:template match="list" mode="short">
+  <xsl:param name="ending">
+    <xsl:text>.</xsl:text>
+  </xsl:param>
+  <xsl:apply-templates mode="short">
+    <xsl:with-param name="ending" select="$ending"/>
+  </xsl:apply-templates>
+</xsl:template>
+<xsl:template match="listitem" mode="short">
+  <xsl:apply-templates mode="short"/><xsl:text>, </xsl:text>
+</xsl:template>
+<xsl:template match="listitem[position() = last()]" mode="short">
+  <xsl:param name="ending">
+    <xsl:text>.</xsl:text>
+  </xsl:param>
+  <xsl:apply-templates mode="short"/><xsl:value-of select="$ending"/>
+</xsl:template>
+<xsl:template match="item" mode="short">
+  <xsl:apply-templates/><xsl:text>, </xsl:text>
+</xsl:template>
+<xsl:template match="item[position() = last()]" mode="short">
+  <xsl:param name="ending">
+    <xsl:text>.</xsl:text>
+  </xsl:param>
+  <xsl:apply-templates/><xsl:value-of select="$ending"/>
+</xsl:template>
+<xsl:template match="organism" mode="short">
+  <xsl:choose>
+    <xsl:when test="web">
+      <a><xsl:attribute name="href">
+         <xsl:apply-templates select="web"/>
+       </xsl:attribute><xsl:apply-templates select="name"/></a>
+    </xsl:when>
+    <xsl:otherwise><xsl:apply-templates select="name"/></xsl:otherwise>
+  </xsl:choose>  
+</xsl:template>
+
+<xsl:template match="ulink">
+  <a>
+    <xsl:attribute name="href">
+      <xsl:value-of select="@url"/>
+    </xsl:attribute>
+    <xsl:apply-templates/>
+  </a>
+</xsl:template>
+
+<xsl:template match="section/title"/>
+<xsl:template match="section/subtitle"/>
+
+
+</xsl:stylesheet>
+