Final (I mean it this time) changes prior to republication
[project-aon.git] / xml / xhtml.xsl
index e05bbde..c06c289 100644 (file)
@@ -9,6 +9,30 @@
 $Id$
 
 $Log$
+Revision 1.15  2007/02/02 20:04:28  jonathan.blake
+Correction to handling line elements
+
+Revision 1.14  2006/12/20 00:15:21  jonathan.blake
+Updated to handle the new capabilities in version 0.12.1 of the Gamebook DTD.
+
+Revision 1.13  2006/11/25 04:47:00  jonathan.blake
+Removal of obsolete apache namespace.
+
+Revision 1.12  2006/06/05 23:46:46  jonathan.blake
+Fixing the handling of titles when <ch.*/> elements are used.
+
+Revision 1.11  2006/04/04 18:48:52  angantyr
+Fixed paragraphed list and illref template bug.
+
+Revision 1.10  2006/04/02 19:14:37  angantyr
+Introduced automatic footnotes list generation and changed the illustrations
+list generation so that links to numbered sections are titled "Section ...".
+Backwards compatible with old XML files.
+
+Revision 1.9  2006/03/14 21:04:03  angantyr
+Changed the illustration handling with the introduction of 'illref's.
+Backwards compatible.
+
 Revision 1.8  2006/03/13 18:38:49  jonathan.blake
 Fixed minor Spanish translation issue
 
@@ -88,7 +112,6 @@ Todo:
 <xsl:transform version="1.0"
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-  xmlns:lxslt="http://xml.apache.org/xslt"
   xmlns:redirect="org.apache.xalan.lib.Redirect"
   extension-element-prefixes="redirect">
 
@@ -161,7 +184,7 @@ Todo:
 <!-- :::::::::::: third-level front matter sections ::::::::::::: -->
 
 <xsl:template match="/gamebook/section/data/section/data/section[@class='frontmatter']">
- <h3><xsl:value-of select="meta/title[1]" /></h3>
+ <h3><xsl:apply-templates select="meta/title[1]" /></h3>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -179,7 +202,7 @@ Todo:
 <!-- :::::::::::: fourth-level front matter sections :::::::::::: -->
 
 <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='frontmatter']">
- <h4><xsl:value-of select="meta/title[1]" /></h4>
+ <h4><xsl:apply-templates select="meta/title[1]" /></h4>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -190,7 +213,7 @@ Todo:
 <!-- ::::::::::::: fifth-level front matter sections :::::::::::: -->
 
 <xsl:template match="/gamebook/section/data/section/data/section/data/section/data/section[@class='frontmatter']">
- <h5><xsl:value-of select="meta/title[1]" /></h5>
+ <h5><xsl:apply-templates select="meta/title[1]" /></h5>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -210,7 +233,7 @@ Todo:
 <!-- :::::::::::: third-level main matter sections ::::::::::::: -->
 
 <xsl:template match="/gamebook/section/data/section/data/section[@class='mainmatter']">
- <h3><xsl:value-of select="meta/title[1]" /></h3>
+ <h3><xsl:apply-templates select="meta/title[1]" /></h3>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -228,7 +251,7 @@ Todo:
 <!-- :::::::::::: fourth-level main matter sections :::::::::::: -->
 
 <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='mainmatter']">
- <h4><xsl:value-of select="meta/title[1]" /></h4>
+ <h4><xsl:apply-templates select="meta/title[1]" /></h4>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -239,7 +262,7 @@ Todo:
 <!-- ::::::::::::: fifth-level main matter sections :::::::::::: -->
 
 <xsl:template match="/gamebook/section/data/section/data/section/data/section/data/section[@class='mainmatter']">
- <h5><xsl:value-of select="meta/title[1]" /></h5>
+ <h5><xsl:apply-templates select="meta/title[1]" /></h5>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -261,7 +284,7 @@ Todo:
 <!-- glossary sections should be enclosed in a second level glossary section -->
 
 <xsl:template match="/gamebook/section/data/section/data/section[@class='glossary']">
- <h3><xsl:value-of select="meta/title[1]" /></h3>
+ <h3><xsl:apply-templates select="meta/title[1]" /></h3>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -307,7 +330,7 @@ Todo:
 <!-- ::::::::::::: third-level back matter sections ::::::::::::: -->
 
 <xsl:template match="/gamebook/section/data/section/data/section[@class='backmatter']">
- <h3><xsl:value-of select="meta/title[1]" /></h3>
+ <h3><xsl:apply-templates select="meta/title[1]" /></h3>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -318,7 +341,7 @@ Todo:
 <!-- ::::::::::::: fourth-level back matter sections ::::::::::::: -->
 
 <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='backmatter']">
- <h4><xsl:value-of select="meta/title[1]" /></h4>
+ <h4><xsl:apply-templates select="meta/title[1]" /></h4>
 
  <xsl:value-of select="$newline" />
  <xsl:value-of select="$newline" />
@@ -340,6 +363,27 @@ Todo:
  </xsl:call-template>
 </xsl:template>
 
+<!-- ::::::::::::::::::::: footnotes template ::::::::::::::::::::::::: -->
+
+<xsl:template match="id( 'footnotz' )">
+ <xsl:choose>
+  <!-- Backwards compatibility measure - if there is data content, use that, otherwise generate footnotes list -->
+  <xsl:when test="count( data/p ) = 0">
+   <xsl:call-template name="xhtml-wrapper">
+    <xsl:with-param name="document-type">footnotz</xsl:with-param>
+    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
+   </xsl:call-template>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:call-template name="xhtml-wrapper">
+    <xsl:with-param name="document-type">second-level-backmatter</xsl:with-param>
+    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
+   </xsl:call-template>
+  </xsl:otherwise>
+ </xsl:choose>
+ <xsl:apply-templates />
+</xsl:template>
+
 <!-- ==================== block elements ======================== -->
 
 <xsl:template match="p">
@@ -353,17 +397,6 @@ Todo:
 </xsl:template>
 
 <xsl:template match="dl[@class='paragraphed']/dd/node() | ol[@class='paragraphed']/li/node() | ul[@class='paragraphed']/li/node()">
- <xsl:variable name="illustration-alt-text">
-  <xsl:choose>
-   <xsl:when test="$language='es'">
-    <xsl:text>ilustraci&oacute;n</xsl:text>
-   </xsl:when>
-   <xsl:otherwise>
-    <xsl:text>illustration</xsl:text>
-   </xsl:otherwise>
-  </xsl:choose>
- </xsl:variable>
-
  <xsl:choose>
   <xsl:when test="self::p">
    <xsl:apply-templates /><br /><br /><xsl:value-of select="$newline" />
@@ -391,34 +424,33 @@ Todo:
    </blockquote><xsl:value-of select="$newline" />
   </xsl:when>
   <xsl:when test="self::illustration">
+   <!-- Backwards compatibility code -->
    <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
    <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
    <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
 
    <xsl:if test="instance[@class='html'] and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
-    <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
-     <table border="0" cellpadding="0" cellspacing="0"><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrtpl.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrtp.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrtpr.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrl.gif" width="32" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" border="0" align="middle" alt="[{$illustration-alt-text}]" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrr.gif" width="32" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrbtl.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrbt.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrbtr.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-     </table><br /><xsl:value-of select="$newline" />
+    <div class="illustration">
+     <div align="center"><xsl:value-of select="$newline" />
+     <xsl:call-template name="illustration-framed">
+      <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
+      <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
+      <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
+     </xsl:call-template>
+     <br /><xsl:value-of select="$newline" />
     </div></div><xsl:value-of select="$newline" />
    </xsl:if>
   </xsl:when>
+  <xsl:when test="self::illref">
+   <xsl:if test="@class='html'">
+    <xsl:for-each select="id( @idref )">
+     <xsl:apply-templates select="." />
+    </xsl:for-each>
+   </xsl:if>
+  </xsl:when>
   <xsl:otherwise>
    <xsl:text>[error: paragraphed list template]</xsl:text>
+   <xsl:message><xsl:text>error: paragraphed list template</xsl:text></xsl:message>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
@@ -460,11 +492,42 @@ Todo:
 
 <xsl:template match="table">
  <table border="1" cellspacing="0" cellpadding="2">
+  <xsl:if test="@summary"><xsl:attribute name="summary"><xsl:value-of select="@summary" /></xsl:attribute></xsl:if>
   <xsl:apply-templates />
  </table>
  <xsl:value-of select="$newline" />
 </xsl:template>
 
+<xsl:template match="caption">
+ <caption>
+  <xsl:apply-templates />
+ </caption>
+</xsl:template>
+
+<xsl:template match="colgroup[@scope]">
+ <colgroup>
+  <xsl:attribute name="scope"><xsl:value-of select="@scope" /></xsl:attribute>
+ </colgroup>
+</xsl:template>
+
+<xsl:template match="thead">
+ <thead>
+  <xsl:apply-templates />
+ </thead>
+</xsl:template>
+
+<xsl:template match="tfoot">
+ <tfoot>
+  <xsl:apply-templates />
+ </tfoot>
+</xsl:template>
+
+<xsl:template match="tbody">
+ <tbody>
+  <xsl:apply-templates />
+ </tbody>
+</xsl:template>
+
 <xsl:template match="tr">
  <tr>
   <xsl:apply-templates />
@@ -476,6 +539,10 @@ Todo:
   <xsl:if test="@align"><xsl:attribute name="align"><xsl:value-of select="@align" /></xsl:attribute></xsl:if>
   <xsl:if test="@valign"><xsl:attribute name="valign"><xsl:value-of select="@valign" /></xsl:attribute></xsl:if>
   <xsl:if test="@char"><xsl:attribute name="char"><xsl:value-of select="@char" /></xsl:attribute></xsl:if>
+  <xsl:if test="@rowspan"><xsl:attribute name="rowspan"><xsl:value-of select="@rowspan" /></xsl:attribute></xsl:if>
+  <xsl:if test="@colspan"><xsl:attribute name="colspan"><xsl:value-of select="@colspan" /></xsl:attribute></xsl:if>
+  <xsl:if test="@axis"><xsl:attribute name="axis"><xsl:value-of select="@axis" /></xsl:attribute></xsl:if>
+  <xsl:if test="@scope"><xsl:attribute name="scope"><xsl:value-of select="@scope" /></xsl:attribute></xsl:if>
   <xsl:apply-templates />
  </th>
 </xsl:template>
@@ -485,6 +552,10 @@ Todo:
   <xsl:if test="@align"><xsl:attribute name="align"><xsl:value-of select="@align" /></xsl:attribute></xsl:if>
   <xsl:if test="@valign"><xsl:attribute name="valign"><xsl:value-of select="@valign" /></xsl:attribute></xsl:if>
   <xsl:if test="@char"><xsl:attribute name="char"><xsl:value-of select="@char" /></xsl:attribute></xsl:if>
+  <xsl:if test="@rowspan"><xsl:attribute name="rowspan"><xsl:value-of select="@rowspan" /></xsl:attribute></xsl:if>
+  <xsl:if test="@colspan"><xsl:attribute name="colspan"><xsl:value-of select="@colspan" /></xsl:attribute></xsl:if>
+  <xsl:if test="@axis"><xsl:attribute name="axis"><xsl:value-of select="@axis" /></xsl:attribute></xsl:if>
+  <xsl:if test="@scope"><xsl:attribute name="scope"><xsl:value-of select="@scope" /></xsl:attribute></xsl:if>
   <xsl:apply-templates />
  </td>
 </xsl:template>
@@ -601,6 +672,82 @@ Todo:
  </blockquote><xsl:value-of select="$newline" />
 </xsl:template>
 
+<xsl:template match="illref">
+ <!-- It is important that the class is not checked right in the template - that would make this template match with higher priority, which will turn a few things upside down --> 
+ <xsl:if test="@class='html'">
+  <xsl:for-each select="id( @idref )">
+   <!-- This creates unneccessary regeneration of float illustration pages, but it is easiest to keep things this way as long as we have to be backwards compatible... -->
+   <!-- When backwards compatibility can be dropped, most of (all?) the <illustration> processing can happen here -->
+   <xsl:apply-templates select="." />
+  </xsl:for-each>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="illustrations">
+ <ul class="unbulleted">
+  <xsl:for-each select="illustration[contains( $use-illustrators, concat( ':', meta/creator, ':' ) )] | illgroup">
+   <xsl:choose>
+    <xsl:when test="self::illustration and @class='float'">
+     <!-- List item with illustration name as link -->
+     <li>
+      <a>
+       <xsl:attribute name="href"><xsl:text>ill</xsl:text><xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )]" from="/" level="any" format="1" /><xsl:text>.htm</xsl:text></xsl:attribute>
+       <xsl:choose>
+        <xsl:when test="$language='es'">
+         <xsl:text>Ilustraci&oacute;n </xsl:text>
+        </xsl:when>
+        <xsl:otherwise>
+         <xsl:text>Illustration </xsl:text>
+        </xsl:otherwise>
+       </xsl:choose>
+       <xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )]" from="/" level="any" format="I" />
+      </a>
+      <!-- List the sections that the illustration appears in -->
+      <xsl:text> (</xsl:text>
+      <xsl:for-each select="//illref[@class='html' and @idref=current()/@id]">
+       <xsl:call-template name="section-title-link" />
+       <xsl:if test="position()!=last()">
+        <xsl:text>, </xsl:text>        
+       </xsl:if>
+      </xsl:for-each>
+      <xsl:text>)</xsl:text><xsl:value-of select="$newline" />
+     </li>
+     <!-- Call the backwards compatible template for generating the illustration page -->
+     <xsl:call-template name="xhtml-wrapper">
+      <xsl:with-param name="document-type">illustration</xsl:with-param>
+      <xsl:with-param name="filename"><xsl:text>ill</xsl:text><xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) ) ]" from="/" level="any" format="1" /></xsl:with-param>
+     </xsl:call-template>
+    </xsl:when>
+
+    <xsl:when test="self::illustration"> <!-- inline and map -->
+     <!-- List the sections that the illustration appears in -->     
+     <li>
+      <!-- TODO: fix this so that sections that do not represent separate XHTML files are not linked to? -->
+      <xsl:for-each select="//illref[@class='html' and @idref=current()/@id]">
+       <xsl:call-template name="section-title-link" />
+       <xsl:if test="position()!=last()">
+        <xsl:text>, </xsl:text>     
+       </xsl:if>
+      </xsl:for-each>
+     </li>
+    </xsl:when>
+
+    <xsl:when test="self::illgroup and @class!='hidden'">
+     <!-- Check if the group contains any illustrations being used, before creating the list item -->
+      <xsl:if test="count( illustration[contains( $use-illustrators, concat( ':', meta/creator, ':' ) )] ) != 0">
+       <li>
+        <a>
+         <xsl:attribute name="href"><xsl:value-of select="@idref" /><xsl:text>.htm</xsl:text></xsl:attribute>
+         <xsl:value-of select="id(@idref)/meta/title[1]" />
+        </a>
+       </li>
+      </xsl:if>
+    </xsl:when>
+   </xsl:choose>
+  </xsl:for-each>
+ </ul><xsl:value-of select="$newline" />
+</xsl:template>
+
 <xsl:template match="illustration">
  <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
  <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
@@ -609,43 +756,20 @@ Todo:
  <xsl:variable name="illustration-width-adjusted"><xsl:number value="$illustration-width div 2" /></xsl:variable>
  <xsl:variable name="illustration-height-adjusted"><xsl:number value="$illustration-height div 2" /></xsl:variable>
 
- <xsl:variable name="illustration-alt-text">
-  <xsl:choose>
-   <xsl:when test="$language='es'">
-    <xsl:text>ilustraci&oacute;n</xsl:text>
-   </xsl:when>
-   <xsl:otherwise>
-    <xsl:text>illustration</xsl:text>
-   </xsl:otherwise>
-  </xsl:choose>
- </xsl:variable>
-
  <xsl:if test="instance[@class='html'] and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
   <xsl:choose>
    <xsl:when test="@class='float'">
-    <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
-     <table border="0" cellpadding="0" cellspacing="0"><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrtpl.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrtp.gif" width="{$illustration-width-adjusted}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrtpr.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrl.gif" width="32" height="{$illustration-height-adjusted}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-        <td>
-        <a>
-         <xsl:attribute name="href"><xsl:text>ill</xsl:text><xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )]" from="/" level="any" format="1" /><xsl:text>.htm</xsl:text></xsl:attribute>
-         <img src="{$illustration-src}" width="{$illustration-width-adjusted}" height="{$illustration-height-adjusted}" border="0" align="middle" alt="[{$illustration-alt-text}]" />
-        </a>
-       </td><xsl:value-of select="$newline" />
-       <td><img src="brdrr.gif" width="32" height="{$illustration-height-adjusted}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrbtl.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrbt.gif" width="{$illustration-width-adjusted}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrbtr.gif" width="32" height="32" align="middle" alt=""/></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-     </table><br /><xsl:value-of select="$newline" />
+    <div class="illustration">
+     <div align="center"><xsl:value-of select="$newline" />
+     <xsl:call-template name="illustration-framed">
+      <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width-adjusted" /></xsl:with-param>
+      <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height-adjusted" /></xsl:with-param>
+      <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
+      <xsl:with-param name="illustration-href">
+       <xsl:text>ill</xsl:text><xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )]" from="/" level="any" format="1" /><xsl:text>.htm</xsl:text>
+      </xsl:with-param>
+     </xsl:call-template>
+     <br /><xsl:value-of select="$newline" />
     </div></div><xsl:value-of select="$newline" />
 
     <xsl:call-template name="xhtml-wrapper">
@@ -657,28 +781,17 @@ Todo:
    <xsl:when test="@class='accent'" />
 
    <xsl:otherwise>
-    <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
-     <table border="0" cellpadding="0" cellspacing="0"><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrtpl.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrtp.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrtpr.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrl.gif" width="32" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" border="0" align="middle" alt="[{$illustration-alt-text}]" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrr.gif" width="32" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-      <tr><xsl:value-of select="$newline" />
-       <td><img src="brdrbtl.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrbt.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-       <td><img src="brdrbtr.gif" width="32" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-      </tr><xsl:value-of select="$newline" />
-     </table><br /><xsl:value-of select="$newline" />
+    <div class="illustration">
+     <div align="center"><xsl:value-of select="$newline" />
+     <xsl:call-template name="illustration-framed">
+      <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
+      <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
+      <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
+     </xsl:call-template>
+     <br /><xsl:value-of select="$newline" />
     </div></div><xsl:value-of select="$newline" />
    </xsl:otherwise>
   </xsl:choose>
-
  </xsl:if>
 </xsl:template>
 
@@ -740,6 +853,7 @@ Todo:
        </xsl:when>
        <xsl:otherwise>
         <xsl:text>[error: a template]</xsl:text>
+        <xsl:message><xsl:text>error: a template</xsl:text></xsl:message>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:attribute>
@@ -753,6 +867,7 @@ Todo:
 
 <!-- This template is obsolete, the "footref" element should be used instead -->
 <xsl:template match="a[@class='footnote']">
+ <!-- <xsl:message><xsl:text>WARNING: Obsolete &lt;a idref='...' class='footnote' /&gt; usage</xsl:text></xsl:message> -->
  <xsl:apply-templates />
  <sup>
   <a>
@@ -763,6 +878,7 @@ Todo:
  </sup>
 </xsl:template>
 
+<!-- TODO: can this be made more uniform with illrefs? -->
 <xsl:template match="a[@class='accent-illustration']">
  <xsl:for-each select="id( @idref )">
   <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
@@ -864,6 +980,11 @@ Todo:
  <tt><xsl:apply-templates /></tt>
 </xsl:template>
 
+<xsl:template match="line">
+ <xsl:apply-templates />
+ <xsl:if test="position( ) != last( )"><br /></xsl:if>
+</xsl:template>
+
 <xsl:template match="br">
  <br />
 </xsl:template>
@@ -1023,7 +1144,7 @@ is included in all copies.
 
    <head><xsl:value-of select="$newline" />
     <title>
-     <xsl:value-of select="/gamebook/meta/title[1]" />
+     <xsl:apply-templates select="/gamebook/meta/title[1]" />
      <xsl:text>: </xsl:text>
      <xsl:choose>
       <xsl:when test="$document-type='illustration'">
@@ -1037,7 +1158,7 @@ is included in all copies.
        </xsl:choose>
        <xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )]" from="/" level="any" format="I" />
       </xsl:when>
-      <xsl:otherwise><xsl:value-of select="meta/title[1]" /></xsl:otherwise>
+      <xsl:otherwise><xsl:apply-templates select="meta/title[1]" /></xsl:otherwise>
      </xsl:choose>
     </title><xsl:value-of select="$newline" />
     <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" /><xsl:value-of select="$newline" />
@@ -1075,7 +1196,7 @@ is included in all copies.
     <xsl:attribute name="vlink"><xsl:value-of select="$vlink-color" /></xsl:attribute>
 
     <xsl:value-of select="$newline" />
-    <div id="title"><img src="title.gif" width="550" height="100" border="0" align="middle" usemap="#imagemap"><xsl:attribute name="alt"><xsl:value-of select="/gamebook/meta/title[1]" /></xsl:attribute></img></div><xsl:value-of select="$newline" />
+    <div id="title"><img src="title.gif" width="550" height="100" border="0" align="middle" usemap="#imagemap"><xsl:attribute name="alt"><xsl:apply-templates select="/gamebook/meta/title[1]" /></xsl:attribute></img></div><xsl:value-of select="$newline" />
     <div id="body"><xsl:value-of select="$newline" />
 
      <xsl:choose>
@@ -1229,7 +1350,7 @@ is included in all copies.
          <xsl:for-each select="/gamebook/section/data/section">
           <li>
            <a><xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:text>.htm</xsl:text></xsl:attribute>
-            <xsl:value-of select="meta/title[1]" />
+            <xsl:apply-templates select="meta/title[1]" />
            </a>
            <xsl:if test="data/section[@class='frontmatter-separate' or @class='mainmatter-separate']">
             <xsl:value-of select="$newline" />
@@ -1257,7 +1378,7 @@ is included in all copies.
 
       <xsl:when test="$document-type='second-level-frontmatter'">
        <div class="frontmatter"><xsl:value-of select="$newline" />
-        <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
+        <h2><xsl:apply-templates select="meta/title" /></h2><xsl:value-of select="$newline" />
 
         <xsl:value-of select="$newline" />
 
@@ -1274,7 +1395,7 @@ is included in all copies.
 
       <xsl:when test="$document-type='third-level-frontmatter-separate'">
        <div class="frontmatter"><xsl:value-of select="$newline" />
-        <h3><xsl:value-of select="meta/title" /></h3><xsl:value-of select="$newline" />
+        <h3><xsl:apply-templates select="meta/title" /></h3><xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
 
         <xsl:apply-templates />
@@ -1290,7 +1411,7 @@ is included in all copies.
 
       <xsl:when test="$document-type='second-level-mainmatter'">
        <div class="mainmatter"><xsl:value-of select="$newline" />
-        <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
+        <h2><xsl:apply-templates select="meta/title" /></h2><xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
 
         <xsl:apply-templates />
@@ -1306,7 +1427,7 @@ is included in all copies.
 
       <xsl:when test="$document-type='third-level-mainmatter-separate'">
        <div class="mainmatter"><xsl:value-of select="$newline" />
-        <h3><xsl:value-of select="meta/title" /></h3><xsl:value-of select="$newline" />
+        <h3><xsl:apply-templates select="meta/title" /></h3><xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
 
         <xsl:apply-templates />
@@ -1322,7 +1443,7 @@ is included in all copies.
 
       <xsl:when test="$document-type='second-level-glossary'">
        <div class="mainmatter"><xsl:value-of select="$newline" />
-        <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
+        <h2><xsl:apply-templates select="meta/title" /></h2><xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
 
         <xsl:apply-templates />
@@ -1342,7 +1463,7 @@ is included in all copies.
 
       <xsl:when test="$document-type='third-level-glossary-separate'">
        <div class="glossary"><xsl:value-of select="$newline" />
-        <h3><xsl:value-of select="meta/title" /></h3><xsl:value-of select="$newline" />
+        <h3><xsl:apply-templates select="meta/title" /></h3><xsl:value-of select="$newline" />
         <xsl:call-template name="alpha-bar">
          <xsl:with-param name="alpha-bar-id-prefix"><xsl:value-of select="$glossary-id-prefix" /></xsl:with-param>
         </xsl:call-template>
@@ -1367,7 +1488,7 @@ title of each section be a simple number.
 -->
       <xsl:when test="$document-type='second-level-numbered'">
        <div class="numbered"><xsl:value-of select="$newline" />
-        <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
+        <h2><xsl:apply-templates select="meta/title" /></h2><xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
 
         <xsl:variable name="base-section-number" select="number( data/section[1]/meta/title ) - 1" />
@@ -1391,7 +1512,7 @@ title of each section be a simple number.
           </xsl:if>
           <a>
            <xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:text>.htm</xsl:text></xsl:attribute>
-           <xsl:value-of select="meta/title" />
+           <xsl:apply-templates select="meta/title" />
           </a>
           <xsl:choose>
            <xsl:when test="position( ) mod 10 = 0">
@@ -1416,7 +1537,7 @@ title of each section be a simple number.
 
       <xsl:when test="$document-type='third-level-numbered'">
        <div class="numbered"><xsl:value-of select="$newline" />
-        <h3><xsl:value-of select="meta/title" /></h3><xsl:value-of select="$newline" />
+        <h3><xsl:apply-templates select="meta/title" /></h3><xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
 
         <xsl:apply-templates />
@@ -1427,11 +1548,63 @@ title of each section be a simple number.
        </div>
       </xsl:when>
 
+<!-- ~~~~~~~~~~~~~~~~~ footnotes ~~~~~~~~~~~~~~~~~~~ -->
+
+      <xsl:when test="$document-type='footnotz'">
+       <div class="backmatter">
+        <xsl:value-of select="$newline" />
+        <!-- No particular reason to code title here -->
+        <h2><xsl:apply-templates select="meta/title" /></h2><xsl:value-of select="$newline" />
+        <xsl:value-of select="$newline" />
+        <xsl:value-of select="$newline" />
+        
+        <!-- Generate list of footnotes -->
+        <xsl:for-each select="//footnotes/footnote">
+         <div class="footnote">
+          <!-- will the list always contain the closest ancestor first? -->
+          <xsl:variable name="footnote-section"><xsl:value-of select="ancestor::section[position()=1]/@id" /></xsl:variable>
+          <xsl:variable name="footnote-marker"><xsl:number count="footnotes/footnote" from="/" level="any" format="1" /></xsl:variable>
+          <xsl:variable name="footnote-idref"><xsl:value-of select="@idref" /></xsl:variable>
+          
+          <xsl:for-each select="*[1]">
+           <p>
+            <xsl:text>[</xsl:text>
+            <a>
+             <xsl:attribute name="href"><xsl:value-of select="$footnote-section" /><xsl:text>.htm#</xsl:text><xsl:value-of select="$footnote-idref" /></xsl:attribute>
+             <xsl:value-of select="$footnote-marker" />
+            </a>
+            <xsl:text>] </xsl:text>
+
+            <xsl:text> (</xsl:text>
+            <xsl:call-template name="section-title-link" />
+            <xsl:text>) </xsl:text>
+
+            <xsl:apply-templates select="child::* | child::text()" />
+           </p>
+          </xsl:for-each>
+          
+          <xsl:for-each select="*[position() != 1]">
+           <xsl:apply-templates select="." />
+          </xsl:for-each>
+          
+         </div>
+        </xsl:for-each>
+        
+        <!-- Backwards compatibility... needed? Probably not. -->
+        <xsl:apply-templates />
+        
+        <xsl:value-of select="$newline" />
+       
+        <xsl:call-template name="navigation-bar" />
+        <xsl:value-of select="$newline" />
+       </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
+      </xsl:when>
+
 <!-- ~~~~~~~~~~~~~~~~~ second-level-backmatter ~~~~~~~~~~~~~~~~~~~ -->
 
       <xsl:when test="$document-type='second-level-backmatter'">
        <div class="frontmatter"><xsl:value-of select="$newline" />
-        <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
+        <h2><xsl:apply-templates select="meta/title" /></h2><xsl:value-of select="$newline" />
 
         <xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
@@ -1449,7 +1622,7 @@ title of each section be a simple number.
 
       <xsl:when test="$document-type='map-adjusted'">
        <div class="frontmatter"><xsl:value-of select="$newline" />
-        <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
+        <h2><xsl:apply-templates select="meta/title" /></h2><xsl:value-of select="$newline" />
 
         <xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
@@ -1466,6 +1639,7 @@ title of each section be a simple number.
           </xsl:choose>
          </xsl:variable>
 
+         <!-- duplicated stuff here, no good way to avoid this while retaining backwards compatibility -->         
          <xsl:choose>
           <xsl:when test="self::illustration and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
            <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
@@ -1476,26 +1650,45 @@ title of each section be a simple number.
            <xsl:variable name="illustration-height-adjusted"><xsl:number value="$illustration-height * $illustration-width-adjusted div $illustration-width" /></xsl:variable>
 
            <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
-            <table border="0" cellpadding="0" cellspacing="0"><xsl:value-of select="$newline" />
-             <tr><xsl:value-of select="$newline" />
-              <td><img src="brdrtpl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><img src="brdrtp.gif" width="{$illustration-width-adjusted}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><img src="brdrtpr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-             </tr><xsl:value-of select="$newline" />
-             <tr><xsl:value-of select="$newline" />
-              <td><img src="brdrl.gif" width="31" height="{$illustration-height-adjusted}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><a href="maplarge.htm"><img src="{$illustration-src}" width="{$illustration-width-adjusted}" height="{$illustration-height-adjusted}" align="middle" border="0" alt="[{$map-illustration-alt-text}]" /></a></td><xsl:value-of select="$newline" />
-              <td><img src="brdrr.gif" width="33" height="{$illustration-height-adjusted}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-             </tr><xsl:value-of select="$newline" />
-             <tr><xsl:value-of select="$newline" />
-              <td><img src="brdrbtl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><img src="brdrbt.gif" width="{$illustration-width-adjusted}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><img src="brdrbtr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-             </tr><xsl:value-of select="$newline" />
-            </table><xsl:value-of select="$newline" />
+            <xsl:call-template name="illustration-framed">
+             <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width-adjusted" /></xsl:with-param>
+             <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height-adjusted" /></xsl:with-param>
+             <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
+             <xsl:with-param name="illustration-href">maplarge.htm</xsl:with-param>
+             <xsl:with-param name="brdrl-width">31</xsl:with-param>
+             <xsl:with-param name="brdrr-width">33</xsl:with-param>
+             <xsl:with-param name="illustration-alt-text">[{$map-illustration-alt-text}]</xsl:with-param>
+            </xsl:call-template>
             <br /><br />
            </div></div><xsl:value-of select="$newline" />
           </xsl:when>
+
+          <xsl:when test="self::illref and @class='html'">
+           <xsl:for-each select="id( @idref )">
+            <xsl:if test="contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
+             <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
+             <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
+             <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
+
+             <xsl:variable name="illustration-width-adjusted"><xsl:number value="386" /></xsl:variable>
+             <xsl:variable name="illustration-height-adjusted"><xsl:number value="$illustration-height * $illustration-width-adjusted div $illustration-width" /></xsl:variable>
+
+             <div class="illustration">
+              <div align="center"><xsl:value-of select="$newline" />
+              <xsl:call-template name="illustration-framed">
+               <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width-adjusted" /></xsl:with-param>
+               <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height-adjusted" /></xsl:with-param>
+               <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
+               <xsl:with-param name="illustration-href">maplarge.htm</xsl:with-param>
+               <xsl:with-param name="brdrl-width">31</xsl:with-param>
+               <xsl:with-param name="brdrr-width">33</xsl:with-param>
+               <xsl:with-param name="illustration-alt-text">[{$map-illustration-alt-text}]</xsl:with-param>
+              </xsl:call-template>
+              <br /><br />
+             </div></div><xsl:value-of select="$newline" />
+            </xsl:if>
+           </xsl:for-each>
+          </xsl:when>
           <xsl:otherwise>
            <xsl:apply-templates select="." />
           </xsl:otherwise>
@@ -1513,7 +1706,7 @@ title of each section be a simple number.
 
       <xsl:when test="$document-type='map'">
        <div class="frontmatter"><xsl:value-of select="$newline" />
-        <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
+        <h2><xsl:apply-templates select="meta/title" /></h2><xsl:value-of select="$newline" />
 
         <xsl:value-of select="$newline" />
         <xsl:value-of select="$newline" />
@@ -1530,6 +1723,7 @@ title of each section be a simple number.
           </xsl:choose>
          </xsl:variable>
 
+         <!-- duplicated stuff here, no good way to avoid this while retaining backwards compatibility -->
          <xsl:choose>
           <xsl:when test="self::illustration and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
            <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
@@ -1537,25 +1731,42 @@ title of each section be a simple number.
            <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
 
            <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
-            <table border="0" cellpadding="0" cellspacing="0"><xsl:value-of select="$newline" />
-             <tr><xsl:value-of select="$newline" />
-              <td><img src="brdrtpl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><img src="brdrtp.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><img src="brdrtpr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-             </tr><xsl:value-of select="$newline" />
-             <tr><xsl:value-of select="$newline" />
-              <td><img src="brdrl.gif" width="31"  height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><a href="map.htm"><img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" align="middle" border="0" alt="[{$map-illustration-alt-text}]" /></a></td><xsl:value-of select="$newline" />
-              <td><img src="brdrr.gif" width="33" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-             </tr><xsl:value-of select="$newline" />
-             <tr><xsl:value-of select="$newline" />
-              <td><img src="brdrbtl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><img src="brdrbt.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-              <td><img src="brdrbtr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-             </tr><xsl:value-of select="$newline" />
-            </table><br /><xsl:value-of select="$newline" />
+            <xsl:call-template name="illustration-framed">
+             <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
+             <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
+             <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
+             <xsl:with-param name="illustration-href">map.htm</xsl:with-param>
+             <xsl:with-param name="brdrl-width">31</xsl:with-param>
+             <xsl:with-param name="brdrr-width">33</xsl:with-param>
+             <xsl:with-param name="illustration-alt-text">[{$map-illustration-alt-text}]</xsl:with-param>
+            </xsl:call-template>
+            <br /><xsl:value-of select="$newline" />
            </div></div><xsl:value-of select="$newline" />
           </xsl:when>
+
+          <xsl:when test="self::illref and @class='html'">
+           <xsl:for-each select="id( @idref )">
+            <xsl:if test="contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
+             <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
+             <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
+             <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
+
+             <div class="illustration">
+              <div align="center"><xsl:value-of select="$newline" />
+              <xsl:call-template name="illustration-framed">
+               <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
+               <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
+               <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
+               <xsl:with-param name="illustration-href">map.htm</xsl:with-param>
+               <xsl:with-param name="brdrl-width">31</xsl:with-param>
+               <xsl:with-param name="brdrr-width">33</xsl:with-param>
+               <xsl:with-param name="illustration-alt-text">[{$map-illustration-alt-text}]</xsl:with-param>
+              </xsl:call-template>
+              <br /><xsl:value-of select="$newline" />
+             </div></div><xsl:value-of select="$newline" />
+            </xsl:if>
+           </xsl:for-each>
+          </xsl:when>
           <xsl:otherwise>
            <xsl:apply-templates select="." />
           </xsl:otherwise>
@@ -1576,17 +1787,6 @@ title of each section be a simple number.
        <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
        <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
 
-       <xsl:variable name="illustration-alt-text">
-        <xsl:choose>
-         <xsl:when test="$language='es'">
-          <xsl:text>ilustraci&oacute;n</xsl:text>
-         </xsl:when>
-         <xsl:otherwise>
-          <xsl:text>illustration</xsl:text>
-         </xsl:otherwise>
-        </xsl:choose>
-       </xsl:variable>
-
        <h3>
         <xsl:choose>
          <xsl:when test="$language='es'">
@@ -1600,23 +1800,14 @@ title of each section be a simple number.
        </h3><xsl:value-of select="$newline" />
 
        <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
-        <table border="0" cellpadding="0" cellspacing="0"><xsl:value-of select="$newline" />
-         <tr><xsl:value-of select="$newline" />
-          <td><img src="brdrtpl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-          <td><img src="brdrtp.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-          <td><img src="brdrtpr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-         </tr><xsl:value-of select="$newline" />
-         <tr><xsl:value-of select="$newline" />
-          <td><img src="brdrl.gif" width="31" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-          <td><img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" align="middle" border="0" alt="[{$illustration-alt-text}]" /></td><xsl:value-of select="$newline" />
-          <td><img src="brdrr.gif" width="33" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-         </tr><xsl:value-of select="$newline" />
-         <tr><xsl:value-of select="$newline" />
-          <td><img src="brdrbtl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-          <td><img src="brdrbt.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-          <td><img src="brdrbtr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
-         </tr><xsl:value-of select="$newline" />
-        </table><br /><xsl:value-of select="$newline" />
+        <xsl:call-template name="illustration-framed">
+         <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
+         <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
+         <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
+         <xsl:with-param name="brdrl-width">31</xsl:with-param>
+         <xsl:with-param name="brdrr-width">33</xsl:with-param>
+        </xsl:call-template>
+        <br /><xsl:value-of select="$newline" />
        </div></div><xsl:value-of select="$newline" />
        <p class="caption"><strong><xsl:apply-templates select="meta/description" /></strong></p><xsl:value-of select="$newline" />
       </xsl:when>
@@ -1649,7 +1840,7 @@ title of each section be a simple number.
     <map name="imagemap" id="imagemap">
      <area shape="rect" coords="0,0,99,99" href="http://www.projectaon.org/" alt="Project Aon" target="_top" />
      <area shape="default" href="title.htm">
-      <xsl:attribute name="alt"><xsl:value-of select="/gamebook/meta/title[1]" /></xsl:attribute>
+      <xsl:attribute name="alt"><xsl:apply-templates select="/gamebook/meta/title[1]" /></xsl:attribute>
      </area>
     </map>
 
@@ -1707,7 +1898,7 @@ title of each section be a simple number.
       <xsl:when test="meta/link[@class='prev']">
        <a>
         <xsl:attribute name="href">
-         <xsl:value-of select="meta/link[@class='prev']/@idref" />
+         <xsl:apply-templates select="meta/link[@class='prev']/@idref" />
          <xsl:text>.htm</xsl:text>
         </xsl:attribute>
         <img src="back.gif" width="150" height="30" border="0">
@@ -1769,4 +1960,84 @@ title of each section be a simple number.
 
 </xsl:template>
 
+<xsl:template name="illustration-framed">
+ <xsl:param name="brdrl-width">32</xsl:param>
+ <xsl:param name="brdr-height">32</xsl:param>
+ <xsl:param name="brdrr-width">32</xsl:param>
+ <xsl:param name="illustration-alt-text">
+  <xsl:choose>
+   <xsl:when test="$language='es'">
+    <xsl:text>ilustraci&oacute;n</xsl:text>
+   </xsl:when>
+   <xsl:otherwise>
+    <xsl:text>illustration</xsl:text>
+   </xsl:otherwise>
+  </xsl:choose>
+ </xsl:param>
+
+ <xsl:param name="illustration-width"></xsl:param>
+ <xsl:param name="illustration-height"></xsl:param>
+ <xsl:param name="illustration-src"></xsl:param>
+ <xsl:param name="illustration-href"></xsl:param>
+
+ <table border="0" cellpadding="0" cellspacing="0">
+  <xsl:value-of select="$newline" />
+  <tr>
+   <xsl:value-of select="$newline" />
+   <td><img src="brdrtpl.gif" width="{$brdrl-width}" height="{$brdr-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
+   <td><img src="brdrtp.gif" width="{$illustration-width}" height="{$brdr-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
+   <td><img src="brdrtpr.gif" width="{$brdrr-width}" height="{$brdr-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
+  </tr><xsl:value-of select="$newline" />
+  <tr>
+   <xsl:value-of select="$newline" />
+   <td><img src="brdrl.gif" width="{$brdrl-width}" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
+   <td>
+    <xsl:choose>
+     <xsl:when test="$illustration-href">
+      <a href="{$illustration-href}">
+       <img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" align="middle" border="0" alt="{$illustration-alt-text}" />
+      </a>
+     </xsl:when>
+     <xsl:otherwise>
+      <img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" align="middle" border="0" alt="[{$illustration-alt-text}]" />
+     </xsl:otherwise>
+    </xsl:choose>
+   </td><xsl:value-of select="$newline" />
+   <td><img src="brdrr.gif" width="{$brdrr-width}" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
+  </tr><xsl:value-of select="$newline" />
+  <tr>
+   <xsl:value-of select="$newline" />
+   <td><img src="brdrbtl.gif" width="{$brdrl-width}" height="{$brdr-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
+   <td><img src="brdrbt.gif" width="{$illustration-width}" height="{$brdr-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
+   <td><img src="brdrbtr.gif" width="{$brdrr-width}" height="{$brdr-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
+  </tr><xsl:value-of select="$newline" />
+ </table><xsl:value-of select="$newline" />
+</xsl:template>
+
+<!--
+ A "subroutine" to generate a link to the current section, with the section title (expanded with "Section " in case of a numbered section) as link text.
+-->
+<xsl:template name="section-title-link">
+ <!-- will the list always contain the closest ancestor first? -->
+ <xsl:variable name="section-title">
+  <!-- numbered or not? -->
+  <xsl:if test="ancestor::section[position()=1]/@class='numbered'">
+   <xsl:choose>
+    <xsl:when test="$language='es'">
+     <xsl:text>Secci&oacute;n </xsl:text>
+    </xsl:when>
+    <xsl:otherwise>
+     <xsl:text>Section </xsl:text>
+    </xsl:otherwise>
+   </xsl:choose>
+  </xsl:if>
+  <xsl:apply-templates select="ancestor::section[position()=1]/meta/title[1]" />
+ </xsl:variable>
+ <a>
+  <xsl:attribute name="href"><xsl:value-of select="ancestor::section[position()=1]/@id" /><xsl:text>.htm</xsl:text></xsl:attribute>
+  <xsl:value-of select="$section-title" />
+ </a>
+</xsl:template>
+
 </xsl:transform>