footnote.xsl 11 KB

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