html.xsl
branchstyles
changeset 0 08de8d15f932
child 3 6e7e05c2ded6
equal deleted inserted replaced
-1:000000000000 0:08de8d15f932
       
     1 <?xml version="1.0"?>
       
     2 <xsl:stylesheet version="1.1"
       
     3   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       
     4   xmlns:xt="http://www.jclark.com/xt"
       
     5   xmlns="http://www.w3.org/1999/xhtml"
       
     6   extension-element-prefixes="xt">
       
     7 
       
     8 <xsl:import href="common.xsl"/>
       
     9 
       
    10   <xsl:output method="xml"
       
    11 	encoding="utf-8"
       
    12         doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
       
    13         doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
       
    14         indent="yes"/>
       
    15 
       
    16 <xsl:param name="css-base-dir"/>
       
    17 <xsl:param name="stylesheet"><xsl:text>html.xsl</xsl:text></xsl:param>
       
    18 <xsl:param name="pdf-filename"><xsl:text>book.pdf</xsl:text></xsl:param>
       
    19 
       
    20 <xsl:template name="get-id">    
       
    21   <xsl:choose>
       
    22     <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when>
       
    23     <xsl:otherwise><xsl:value-of select="generate-id(.)"/></xsl:otherwise>
       
    24   </xsl:choose>
       
    25 </xsl:template>
       
    26 <xsl:template name="parent-id">
       
    27   <xsl:choose>
       
    28     <xsl:when test="../@id"><xsl:value-of select="../@id"/></xsl:when>
       
    29     <xsl:otherwise><xsl:value-of select="generate-id(..)"/></xsl:otherwise>
       
    30   </xsl:choose>
       
    31 </xsl:template>
       
    32 <xsl:template name="next-id">
       
    33   <xsl:choose>
       
    34     <xsl:when test="following::*[1]/@id"><xsl:value-of select="following::*[1]/@id"/></xsl:when>
       
    35     <xsl:otherwise><xsl:value-of select="generate-id(following::*[1])"/></xsl:otherwise>
       
    36   </xsl:choose>
       
    37 </xsl:template>
       
    38 <xsl:template name="prec-id">
       
    39   <xsl:choose>
       
    40     <xsl:when test="preceding::*[1]/@id"><xsl:value-of select="preceding::*[1]/@id"/></xsl:when>
       
    41     <xsl:otherwise><xsl:value-of select="generate-id(preceding::*[1])"/></xsl:otherwise>
       
    42   </xsl:choose>
       
    43 </xsl:template>
       
    44 
       
    45 <!-- book processing -->
       
    46 <xsl:template match="book">
       
    47   <html>
       
    48     <head>
       
    49       <xsl:choose>
       
    50         <xsl:when test="docinfo">
       
    51            <xsl:apply-templates select="docinfo" mode="heading"/> 
       
    52         </xsl:when>
       
    53         <xsl:otherwise>
       
    54           <xsl:apply-templates select="title" mode="heading"/>
       
    55         </xsl:otherwise>
       
    56       </xsl:choose>
       
    57       <link href="{$css-base-dir}{$stylesheet}" media="screen" rel="stylesheet" type="text/css"/>
       
    58     </head>
       
    59     <body class="book">
       
    60       <xsl:apply-templates select="docinfo/date"/>
       
    61       <xsl:apply-templates/>
       
    62       <xsl:apply-templates mode="book-toc"/>
       
    63       <hr/>
       
    64       <address>
       
    65         <xsl:apply-templates select="docinfo/copyright"/>
       
    66 	<p>Aussi disponible au format <a href="{$pdf-filename}">PDF</a>.</p>
       
    67       </address>
       
    68     </body>
       
    69   </html>
       
    70 </xsl:template>
       
    71 
       
    72 <xsl:template match="book/section" mode="book-toc">
       
    73   <xsl:variable name="href">
       
    74     <xsl:call-template name="get-id"/>
       
    75   </xsl:variable>
       
    76   <h2>
       
    77     <a id="{$href}" href="{$href}.html">
       
    78       <xsl:apply-templates select="title" mode="book-toc"/>
       
    79     </a>
       
    80   </h2>
       
    81 </xsl:template>
       
    82 
       
    83 <!-- title default processing -->
       
    84 <xsl:template match="title">
       
    85   <h1><xsl:apply-templates/></h1>
       
    86 </xsl:template>
       
    87 <xsl:template match="subtitle">
       
    88   <p class="subtitle"><em><xsl:apply-templates/></em></p>
       
    89 </xsl:template>
       
    90 
       
    91 <!-- normal name processing -->
       
    92 <xsl:template name="name">
       
    93   <xsl:variable name="fullname">
       
    94      <xsl:apply-templates select="firstname"/>
       
    95      <xsl:if test="initials">
       
    96        <xsl:text> </xsl:text>
       
    97        <xsl:apply-templates select="initials"/>
       
    98      </xsl:if>
       
    99      <xsl:text> </xsl:text>
       
   100      <xsl:apply-templates select="surname"/>    
       
   101   </xsl:variable>
       
   102   <xsl:choose>
       
   103   <xsl:when test="email">
       
   104     <a href="mailto:{email/text()}" class="mailto">
       
   105       <xsl:value-of select="$fullname"/>
       
   106     </a>
       
   107   </xsl:when>
       
   108   <xsl:otherwise>
       
   109     <xsl:value-of select="$fullname"/>
       
   110   </xsl:otherwise>
       
   111   </xsl:choose>           
       
   112 </xsl:template>
       
   113 
       
   114 <xsl:template match="*" mode="fullname">
       
   115   <xsl:call-template name="name"/>  
       
   116 </xsl:template>
       
   117 <xsl:template match="email">
       
   118   <a href="mailto:{.}"><xsl:value-of select="."/></a>
       
   119 </xsl:template>
       
   120 <xsl:template match="web">
       
   121   <a href="{.}"><xsl:value-of select="."/></a>
       
   122 </xsl:template>
       
   123 <!-- simple address format, good for Canada -->
       
   124 <xsl:template match="address">
       
   125   <xsl:apply-templates mode="address" select="street"/>
       
   126   <xsl:value-of select="city"/>
       
   127   (<xsl:value-of select="state"/>),
       
   128   <xsl:value-of select="postcode"/><br/>
       
   129   <xsl:apply-templates select="country" mode="address"/>    
       
   130 </xsl:template>
       
   131 <xsl:template match="*" mode="address">
       
   132   <xsl:apply-templates/><br/>
       
   133 </xsl:template>
       
   134 
       
   135 <!-- default docinfo processing -->
       
   136 <!-- normal is not process -->
       
   137 <xsl:template match="docinfo"/>
       
   138 <!-- date processing if directly selected -->
       
   139 <xsl:template match="date">
       
   140   <address class="date">
       
   141     <xsl:apply-templates/>
       
   142   </address>
       
   143 </xsl:template>
       
   144 <!-- in heading, default is to not process. -->
       
   145 <xsl:template match="*" mode="heading"/>
       
   146 <xsl:template match="docinfo" mode="heading">
       
   147   <xsl:apply-templates mode="heading"/>
       
   148 </xsl:template>
       
   149 <xsl:template match="title" mode="heading">
       
   150   <title><xsl:apply-templates/></title>
       
   151 </xsl:template>
       
   152 <xsl:template match="author" mode="heading">
       
   153   <meta name="author">
       
   154     <xsl:attribute name="content">
       
   155       <xsl:if test="firstname">
       
   156         <xsl:apply-templates select="firstname"/><xsl:text> </xsl:text>
       
   157       </xsl:if>
       
   158       <xsl:if test="initials">
       
   159         <xsl:apply-templates select="initials"/><xsl:text> </xsl:text>
       
   160       </xsl:if>
       
   161       <xsl:apply-templates select="surname"/>
       
   162     </xsl:attribute>
       
   163   </meta>
       
   164 </xsl:template>
       
   165 <xsl:template match="date" mode="heading">
       
   166   <meta name="date" content="{text()}"/>
       
   167 </xsl:template>
       
   168 
       
   169 <!-- copyright footer processing -->
       
   170 <xsl:template match="copyright">
       
   171   © <xsl:apply-templates select="holder"/>
       
   172   <xsl:text> </xsl:text>
       
   173   <xsl:apply-templates select="year"/>
       
   174 </xsl:template>
       
   175 <xsl:template match="holder">
       
   176   <xsl:call-template name="name"/>
       
   177 </xsl:template>
       
   178 <xsl:template match="year">
       
   179   <xsl:apply-templates/>
       
   180   <xsl:if test="position() != last()">
       
   181     <xsl:text>, </xsl:text>
       
   182   </xsl:if>
       
   183 </xsl:template>
       
   184 
       
   185 <!-- nda docinfo processing -->
       
   186 <xsl:template match="*" mode="heading-nda"/>
       
   187 <xsl:template match="title" mode="heading-nda">
       
   188   <title>
       
   189     <xsl:apply-templates/><xsl:text> (Notes de l'auteur)</xsl:text>
       
   190   </title>
       
   191 </xsl:template>
       
   192 <xsl:template match="docinfo" mode="heading-nda">
       
   193   <xsl:apply-templates mode="heading-nda"/>
       
   194   <xsl:apply-templates select='*[name()!="title"]' mode="heading"/> 
       
   195 </xsl:template>
       
   196 
       
   197 <!-- para default processing -->
       
   198 <xsl:template match="para">
       
   199   <p><xsl:apply-templates/></p>
       
   200 </xsl:template>
       
   201 
       
   202 <!-- formalpara processing -->
       
   203 <xsl:template match="formalpara/para">
       
   204   <xsl:apply-templates/>
       
   205 </xsl:template>
       
   206 <xsl:template match="formalpara/title">
       
   207   <strong><xsl:apply-templates/></strong>
       
   208 </xsl:template>
       
   209 <xsl:template match="formalpara">
       
   210   <p><xsl:apply-templates/></p>
       
   211 </xsl:template>
       
   212 
       
   213 <!-- citation -->
       
   214 <xsl:template match="citation/author">
       
   215   <address><xsl:apply-templates/></address>
       
   216 </xsl:template>
       
   217 <xsl:template match="citation">
       
   218   <blockquote><xsl:apply-templates/></blockquote>
       
   219 </xsl:template>
       
   220 <xsl:template match="author/surname">
       
   221   <xsl:apply-templates/>
       
   222   <xsl:if test="following-sibling::author">
       
   223     <xsl:text>, </xsl:text>
       
   224   </xsl:if>
       
   225 </xsl:template>
       
   226 <xsl:template match="author/title">
       
   227   <xsl:apply-templates/>
       
   228 </xsl:template>
       
   229 
       
   230 <!-- list processing -->
       
   231 <xsl:template match="list">
       
   232   <xsl:choose>
       
   233     <xsl:when test="@type='none'">
       
   234       <ul>
       
   235         <xsl:apply-templates/>
       
   236       </ul>
       
   237     </xsl:when>
       
   238     <xsl:otherwise>
       
   239       <ol type="{@id}">
       
   240         <xsl:apply-templates/>
       
   241       </ol>
       
   242     </xsl:otherwise>
       
   243   </xsl:choose>
       
   244 </xsl:template>
       
   245 <xsl:template match="shortlist">
       
   246   <p><xsl:apply-templates mode="short"/></p>
       
   247 </xsl:template>
       
   248 
       
   249 <xsl:template match="item|listitem">
       
   250   <li><xsl:apply-templates/></li>
       
   251 </xsl:template>
       
   252 
       
   253 <!-- inline element -->
       
   254 <xsl:template match="emphasis">
       
   255   <em><xsl:apply-templates/></em>
       
   256 </xsl:template>
       
   257 <xsl:template match="term">
       
   258   <em class="term"><xsl:apply-templates/></em>
       
   259 </xsl:template>
       
   260 <xsl:template match="foreign">
       
   261   <em class="foreign"><xsl:apply-templates/></em>
       
   262 </xsl:template>
       
   263 <xsl:template match="replaceable">
       
   264   <em class="replaceable">
       
   265     <xsl:text>[</xsl:text>
       
   266     <xsl:apply-templates/>
       
   267     <xsl:text>]</xsl:text>
       
   268   </em>
       
   269 </xsl:template>
       
   270 <xsl:template match="literal">
       
   271   <tt class="literal"><xsl:apply-templates/></tt>
       
   272 </xsl:template>
       
   273 <xsl:template match="acronym[@text]">
       
   274   <acronym title="{@text}"><xsl:apply-templates/></acronym>
       
   275 </xsl:template>
       
   276 <xsl:template match="acronym">
       
   277   <acronym><xsl:apply-templates/></acronym>
       
   278 </xsl:template>
       
   279 
       
   280 <xsl:template match="subscript">
       
   281   <sub><xsl:apply-templates/></sub>
       
   282 </xsl:template>
       
   283 <xsl:template match="superscript">
       
   284   <sup><xsl:apply-templates/></sup>
       
   285 </xsl:template>
       
   286 
       
   287 <xsl:template match="section" mode="navbar-name">
       
   288   <xsl:value-of select="title/text()"/>
       
   289 </xsl:template>
       
   290 
       
   291 <xsl:template match="section|story|poetry" mode="navbar-link">
       
   292   <xsl:call-template name="get-id"/>
       
   293 </xsl:template>
       
   294 
       
   295 <xsl:template name="navbar-link">
       
   296   <xsl:param name="prefix"></xsl:param>
       
   297   <a>
       
   298     <xsl:attribute name="href">
       
   299       <xsl:apply-templates select="." mode="navbar-link"/>
       
   300       <xsl:text>.html</xsl:text>
       
   301     </xsl:attribute>
       
   302     <xsl:value-of select="$prefix"/>
       
   303     <xsl:apply-templates select="." mode="navbar-name"/>
       
   304   </a><br/>
       
   305 </xsl:template>
       
   306 
       
   307 <xsl:template match="section" mode="navbar-prec">
       
   308   <xsl:call-template name="navbar-link">
       
   309     <xsl:with-param name="prefix">
       
   310       <xsl:text>Section précédente: </xsl:text>
       
   311     </xsl:with-param>
       
   312   </xsl:call-template>
       
   313 </xsl:template>
       
   314 <xsl:template match="section" mode="navbar-next">
       
   315   <xsl:call-template name="navbar-link">
       
   316     <xsl:with-param name="prefix">
       
   317       <xsl:text>Section suivante: </xsl:text>
       
   318     </xsl:with-param>
       
   319   </xsl:call-template>
       
   320 </xsl:template>
       
   321 
       
   322 <xsl:template match="section" mode="navbar-section">
       
   323    <xsl:apply-templates 
       
   324      select="preceding-sibling::section[1]"
       
   325      mode="navbar-prec"/>
       
   326    <xsl:apply-templates 
       
   327      select="following-sibling::section[1]"
       
   328      mode="navbar-next"/>
       
   329   <xsl:variable name="section-ref">
       
   330     <xsl:call-template name="get-id"/>
       
   331   </xsl:variable>
       
   332   <a href="index.html#{$section-ref}">Retour à la table des matières</a><br/>
       
   333 </xsl:template>
       
   334 
       
   335 <!-- The book-toc section -->
       
   336 <xsl:template match="book/section">
       
   337   <xsl:variable name="href">
       
   338     <xsl:call-template name="get-id"/>
       
   339   </xsl:variable>
       
   340   <xt:document href="{$href}.html" method="xml" encoding="utf-8"
       
   341         doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
       
   342         doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
       
   343         indent="yes">
       
   344     <html>
       
   345       <head>
       
   346         <xsl:apply-templates select="title" mode="heading"/>
       
   347         <link href="{$css-base-dir}{$stylesheet}" media="screen" rel="stylesheet" type="text/css"/>
       
   348       </head>
       
   349       <body>
       
   350         <h1><xsl:value-of select="title"/></h1>
       
   351         <xsl:apply-templates select="child::*[name(.) != 'story' or name(.)!= 'poetry']"/>
       
   352         <ul>
       
   353           <xsl:apply-templates mode="section-toc"/>
       
   354         </ul>
       
   355         <hr/>
       
   356         <address>
       
   357           <xsl:apply-templates select="../copyright"/>
       
   358         </address>
       
   359         <xsl:apply-templates mode="navbar-section" select="."/>
       
   360       </body>
       
   361     </html>
       
   362   </xt:document>
       
   363   <xsl:apply-templates select="story|poetry"/>
       
   364 </xsl:template>
       
   365 
       
   366 <xsl:template match="section/title" mode="book-toc">
       
   367   <xsl:apply-templates/>
       
   368 </xsl:template>
       
   369 
       
   370 <!-- anything else is clear -->
       
   371 <xsl:template match="*" mode="book-toc"/>
       
   372 <xsl:template match="*" mode="section-toc"/>
       
   373 <xsl:template match="*" mode="navbar-section"/>
       
   374 
       
   375 <!-- preambule section -->
       
   376 <xsl:template match="preambule">
       
   377   <xsl:apply-templates/>
       
   378 </xsl:template>
       
   379 
       
   380 <xsl:template match="preambule/title">
       
   381   <h2><xsl:apply-templates/></h2>
       
   382 </xsl:template>
       
   383 
       
   384 <!-- short representation -->
       
   385 <xsl:template match="list" mode="short">
       
   386   <xsl:param name="ending">
       
   387     <xsl:text>.</xsl:text>
       
   388   </xsl:param>
       
   389   <xsl:apply-templates mode="short">
       
   390     <xsl:with-param name="ending" select="$ending"/>
       
   391   </xsl:apply-templates>
       
   392 </xsl:template>
       
   393 <xsl:template match="listitem" mode="short">
       
   394   <xsl:apply-templates mode="short"/><xsl:text>, </xsl:text>
       
   395 </xsl:template>
       
   396 <xsl:template match="listitem[position() = last()]" mode="short">
       
   397   <xsl:param name="ending">
       
   398     <xsl:text>.</xsl:text>
       
   399   </xsl:param>
       
   400   <xsl:apply-templates mode="short"/><xsl:value-of select="$ending"/>
       
   401 </xsl:template>
       
   402 <xsl:template match="item" mode="short">
       
   403   <xsl:apply-templates/><xsl:text>, </xsl:text>
       
   404 </xsl:template>
       
   405 <xsl:template match="item[position() = last()]" mode="short">
       
   406   <xsl:param name="ending">
       
   407     <xsl:text>.</xsl:text>
       
   408   </xsl:param>
       
   409   <xsl:apply-templates/><xsl:value-of select="$ending"/>
       
   410 </xsl:template>
       
   411 <xsl:template match="organism" mode="short">
       
   412   <xsl:choose>
       
   413     <xsl:when test="web">
       
   414       <a><xsl:attribute name="href">
       
   415          <xsl:apply-templates select="web"/>
       
   416        </xsl:attribute><xsl:apply-templates select="name"/></a>
       
   417     </xsl:when>
       
   418     <xsl:otherwise><xsl:apply-templates select="name"/></xsl:otherwise>
       
   419   </xsl:choose>  
       
   420 </xsl:template>
       
   421 
       
   422 <xsl:template match="ulink">
       
   423   <a>
       
   424     <xsl:attribute name="href">
       
   425       <xsl:value-of select="@url"/>
       
   426     </xsl:attribute>
       
   427     <xsl:apply-templates/>
       
   428   </a>
       
   429 </xsl:template>
       
   430 
       
   431 <xsl:template match="section/title"/>
       
   432 <xsl:template match="section/subtitle"/>
       
   433 
       
   434 
       
   435 </xsl:stylesheet>
       
   436