$Id$
$Log$
+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.
<!-- :::::::::::: 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" />
<!-- :::::::::::: 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" />
<!-- ::::::::::::: 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" />
<!-- :::::::::::: 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" />
<!-- :::::::::::: 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" />
<!-- ::::::::::::: 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" />
<!-- 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" />
<!-- ::::::::::::: 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" />
<!-- ::::::::::::: 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" />
</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">
</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" />
</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>
</blockquote><xsl:value-of select="$newline" />
</xsl:template>
-<xsl:template match="illref[@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: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">
<!-- List the sections that the illustration appears in -->
<xsl:text> (</xsl:text>
<xsl:for-each select="//illref[@class='html' and @idref=current()/@id]">
- <!-- will the list always contain the closest ancestor first??? -->
- <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="ancestor::section[position()=1]/meta/title[1]" />
- </a>
+ <xsl:call-template name="section-title-link" />
<xsl:if test="position()!=last()">
- <xsl:text>, </xsl:text>
+ <xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>)</xsl:text><xsl:value-of select="$newline" />
<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]">
- <!-- will the list always contain the closest ancestor first? -->
- <a>
- <!-- TODO: fix this so that sections that do not represent separate XHTML files are not linked to -->
- <xsl:attribute name="href"><xsl:value-of select="ancestor::section[position()=1]/@id" /><xsl:text>.htm</xsl:text></xsl:attribute>
- <xsl:value-of select="ancestor::section[position()=1]/meta/title[1]" />
- </a>
+ <xsl:call-template name="section-title-link" />
<xsl:if test="position()!=last()">
- <xsl:text>, </xsl:text>
+ <xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</li>
</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>
<!-- This template is obsolete, the "footref" element should be used instead -->
<xsl:template match="a[@class='footnote']">
+ <!-- <xsl:message><xsl:text>WARNING: Obsolete <a idref='...' class='footnote' /> usage</xsl:text></xsl:message> -->
<xsl:apply-templates />
<sup>
<a>
<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'">
</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" />
<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>
<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" />
<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" />
<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 />
<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 />
<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 />
<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 />
<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>
-->
<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" />
</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">
<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 />
</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" />
<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" />
<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" />
<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>
<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">
</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ó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>