footnote.xsl 12 KB

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