1<?xml version='1.0'?> 2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 xmlns:exsl="http://exslt.org/common" 4 exclude-result-prefixes="exsl" 5 version='1.0'> 6 7<!-- ******************************************************************** 8 $Id: footnote.xsl,v 1.19 2005/07/14 14:30:43 nwalsh Exp $ 9 ******************************************************************** 10 11 This file is part of the XSL DocBook Stylesheet distribution. 12 See /README or http://nwalsh.com/docbook/xsl/ for copyright 13 and other information. 14 15 ******************************************************************** --> 16 17<xsl:template match="footnote"> 18 <xsl:variable name="name"> 19 <xsl:call-template name="object.id"/> 20 </xsl:variable> 21 <xsl:variable name="href"> 22 <xsl:text>#ftn.</xsl:text> 23 <xsl:call-template name="object.id"/> 24 </xsl:variable> 25 26 <xsl:choose> 27 <xsl:when test="ancestor::tgroup"> 28 <sup> 29 <xsl:text>[</xsl:text> 30 <a name="{$name}" href="{$href}"> 31 <xsl:apply-templates select="." mode="footnote.number"/> 32 </a> 33 <xsl:text>]</xsl:text> 34 </sup> 35 </xsl:when> 36 <xsl:otherwise> 37 <sup> 38 <xsl:text>[</xsl:text> 39 <a name="{$name}" href="{$href}"> 40 <xsl:apply-templates select="." mode="footnote.number"/> 41 </a> 42 <xsl:text>]</xsl:text> 43 </sup> 44 </xsl:otherwise> 45 </xsl:choose> 46</xsl:template> 47 48<xsl:template match="footnoteref"> 49 <xsl:variable name="targets" select="key('id',@linkend)"/> 50 <xsl:variable name="footnote" select="$targets[1]"/> 51 <xsl:variable name="href"> 52 <xsl:text>#ftn.</xsl:text> 53 <xsl:call-template name="object.id"> 54 <xsl:with-param name="object" select="$footnote"/> 55 </xsl:call-template> 56 </xsl:variable> 57 <sup> 58 <xsl:text>[</xsl:text> 59 <a href="{$href}"> 60 <xsl:apply-templates select="$footnote" mode="footnote.number"/> 61 </a> 62 <xsl:text>]</xsl:text> 63 </sup> 64</xsl:template> 65 66<xsl:template match="footnote" mode="footnote.number"> 67 <xsl:choose> 68 <xsl:when test="string-length(@label) != 0"> 69 <xsl:value-of select="@label"/> 70 </xsl:when> 71 <xsl:when test="ancestor::tgroup"> 72 <xsl:variable name="tfnum"> 73 <xsl:number level="any" from="table|informaltable" format="1"/> 74 </xsl:variable> 75 76 <xsl:choose> 77 <xsl:when test="string-length($table.footnote.number.symbols) >= $tfnum"> 78 <xsl:value-of select="substring($table.footnote.number.symbols, $tfnum, 1)"/> 79 </xsl:when> 80 <xsl:otherwise> 81 <xsl:number level="any" from="tgroup" 82 format="{$table.footnote.number.format}"/> 83 </xsl:otherwise> 84 </xsl:choose> 85 </xsl:when> 86 <xsl:otherwise> 87 <xsl:variable name="pfoot" select="preceding::footnote[not(@label)]"/> 88 <xsl:variable name="ptfoot" select="preceding::tgroup//footnote"/> 89 <xsl:variable name="fnum" select="count($pfoot) - count($ptfoot) + 1"/> 90 91 <xsl:choose> 92 <xsl:when test="string-length($footnote.number.symbols) >= $fnum"> 93 <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/> 94 </xsl:when> 95 <xsl:otherwise> 96 <xsl:number value="$fnum" format="{$footnote.number.format}"/> 97 </xsl:otherwise> 98 </xsl:choose> 99 </xsl:otherwise> 100 </xsl:choose> 101</xsl:template> 102 103<!-- ==================================================================== --> 104 105<xsl:template match="footnote/para[1]|footnote/simpara[1]" priority="2"> 106 <!-- this only works if the first thing in a footnote is a para, --> 107 <!-- which is ok, because it usually is. --> 108 <xsl:variable name="name"> 109 <xsl:text>ftn.</xsl:text> 110 <xsl:call-template name="object.id"> 111 <xsl:with-param name="object" select="ancestor::footnote"/> 112 </xsl:call-template> 113 </xsl:variable> 114 <xsl:variable name="href"> 115 <xsl:text>#</xsl:text> 116 <xsl:call-template name="object.id"> 117 <xsl:with-param name="object" select="ancestor::footnote"/> 118 </xsl:call-template> 119 </xsl:variable> 120 <p> 121 <xsl:if test="@role and $para.propagates.style != 0"> 122 <xsl:attribute name="class"> 123 <xsl:value-of select="@role"/> 124 </xsl:attribute> 125 </xsl:if> 126 <sup> 127 <xsl:text>[</xsl:text> 128 <a name="{$name}" href="{$href}"> 129 <xsl:apply-templates select="ancestor::footnote" 130 mode="footnote.number"/> 131 </a> 132 <xsl:text>] </xsl:text> 133 </sup> 134 <xsl:apply-templates/> 135 </p> 136</xsl:template> 137 138<!-- ==================================================================== --> 139 140<xsl:template match="*" mode="footnote.body.number"> 141 <xsl:variable name="name"> 142 <xsl:text>ftn.</xsl:text> 143 <xsl:call-template name="object.id"> 144 <xsl:with-param name="object" select="ancestor::footnote"/> 145 </xsl:call-template> 146 </xsl:variable> 147 <xsl:variable name="href"> 148 <xsl:text>#</xsl:text> 149 <xsl:call-template name="object.id"> 150 <xsl:with-param name="object" select="ancestor::footnote"/> 151 </xsl:call-template> 152 </xsl:variable> 153 <xsl:variable name="footnote.mark"> 154 <sup> 155 <xsl:text>[</xsl:text> 156 <a name="{$name}" href="{$href}"> 157 <xsl:apply-templates select="ancestor::footnote" 158 mode="footnote.number"/> 159 </a> 160 <xsl:text>] </xsl:text> 161 </sup> 162 </xsl:variable> 163 164 <xsl:variable name="html"> 165 <xsl:apply-templates select="."/> 166 </xsl:variable> 167 168 <xsl:choose> 169 <xsl:when test="function-available('exsl:node-set')"> 170 <xsl:variable name="html-nodes" select="exsl:node-set($html)"/> 171 <xsl:choose> 172 <xsl:when test="$html-nodes//p"> 173 <xsl:apply-templates select="$html-nodes" mode="insert.html.p"> 174 <xsl:with-param name="mark" select="$footnote.mark"/> 175 </xsl:apply-templates> 176 </xsl:when> 177 <xsl:otherwise> 178 <xsl:apply-templates select="$html-nodes" mode="insert.html.text"> 179 <xsl:with-param name="mark" select="$footnote.mark"/> 180 </xsl:apply-templates> 181 </xsl:otherwise> 182 </xsl:choose> 183 </xsl:when> 184 <xsl:otherwise> 185 <xsl:copy-of select="$html"/> 186 </xsl:otherwise> 187 </xsl:choose> 188</xsl:template> 189 190<!-- ==================================================================== --> 191 192<!-- 193<xsl:template name="count-element-from"> 194 <xsl:param name="from" select=".."/> 195 <xsl:param name="to" select="."/> 196 <xsl:param name="count" select="0"/> 197 <xsl:param name="list" select="$from/following::*[name(.)=name($to)] 198 |$from/descendant-or-self::*[name(.)=name($to)]"/> 199 200 <xsl:choose> 201 <xsl:when test="not($list)"> 202 <xsl:text>-1</xsl:text> 203 </xsl:when> 204 <xsl:when test="$list[1] = $to"> 205 <xsl:value-of select="$count + 1"/> 206 </xsl:when> 207 <xsl:otherwise> 208 </xsl:otherwise> 209 </xsl:choose> 210</xsl:template> 211--> 212 213<!-- ==================================================================== --> 214 215<xsl:template name="process.footnotes"> 216 <xsl:variable name="footnotes" select=".//footnote"/> 217 <xsl:variable name="table.footnotes" 218 select=".//tgroup//footnote"/> 219 220 <!-- Only bother to do this if there's at least one non-table footnote --> 221 <xsl:if test="count($footnotes)>count($table.footnotes)"> 222 <div class="footnotes"> 223 <br/> 224 <hr width="100" align="left"/> 225 <xsl:apply-templates select="$footnotes" mode="process.footnote.mode"/> 226 </div> 227 </xsl:if> 228 229 <xsl:if test="$annotation.support != 0 and //annotation"> 230 <div class="annotation-list"> 231 <div class="annotation-nocss"> 232 <p>The following annotations are from this essay. You are seeing 233 them here because your browser doesn’t support the user-interface 234 techniques used to make them appear as ‘popups’ on modern browsers.</p> 235 </div> 236 237 <xsl:apply-templates select="//annotation" 238 mode="annotation-popup"/> 239 </div> 240 </xsl:if> 241</xsl:template> 242 243<xsl:template name="process.chunk.footnotes"> 244 <!-- nop --> 245</xsl:template> 246 247<xsl:template match="footnote" name="process.footnote" mode="process.footnote.mode"> 248 <xsl:choose> 249 <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'"> 250 <div class="{name(.)}"> 251 <xsl:apply-templates/> 252 </div> 253 </xsl:when> 254 255 <xsl:when test="$html.cleanup != 0 and function-available('exsl:node-set')"> 256 <div class="{name(.)}"> 257 <xsl:apply-templates select="*[1]" mode="footnote.body.number"/> 258 <xsl:apply-templates select="*[position() > 1]"/> 259 </div> 260 </xsl:when> 261 262 <xsl:otherwise> 263 <xsl:message> 264 <xsl:text>Warning: footnote number may not be generated </xsl:text> 265 <xsl:text>correctly; </xsl:text> 266 <xsl:value-of select="local-name(*[1])"/> 267 <xsl:text> unexpected as first child of footnote.</xsl:text> 268 </xsl:message> 269 <div class="{name(.)}"> 270 <xsl:apply-templates/> 271 </div> 272 </xsl:otherwise> 273 </xsl:choose> 274</xsl:template> 275 276<xsl:template match="tgroup//footnote" 277 mode="process.footnote.mode"> 278</xsl:template> 279 280<xsl:template match="footnote" mode="table.footnote.mode"> 281 <xsl:call-template name="process.footnote"/> 282</xsl:template> 283 284</xsl:stylesheet> 285