footnote.xsl 9.7 KB

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