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