footnote.xsl 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. xmlns:xlink="http://www.w3.org/1999/xlink"
  5. xmlns:exsl="http://exslt.org/common"
  6. exclude-result-prefixes="exsl xlink"
  7. version='1.0'>
  8. <!-- ********************************************************************
  9. $Id: footnote.xsl 8359 2009-03-20 18:42:06Z bobstayton $
  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. <xsl:template name="format.footnote.mark">
  16. <xsl:param name="mark" select="'?'"/>
  17. <fo:inline xsl:use-attribute-sets="footnote.mark.properties">
  18. <xsl:choose>
  19. <xsl:when test="$fop.extensions != 0">
  20. <xsl:attribute name="vertical-align">super</xsl:attribute>
  21. </xsl:when>
  22. <xsl:otherwise>
  23. <xsl:attribute name="baseline-shift">super</xsl:attribute>
  24. </xsl:otherwise>
  25. </xsl:choose>
  26. <xsl:copy-of select="$mark"/>
  27. </fo:inline>
  28. </xsl:template>
  29. <xsl:template match="footnote">
  30. <xsl:choose>
  31. <xsl:when test="ancestor::table or ancestor::informaltable">
  32. <xsl:call-template name="format.footnote.mark">
  33. <xsl:with-param name="mark">
  34. <xsl:apply-templates select="." mode="footnote.number"/>
  35. </xsl:with-param>
  36. </xsl:call-template>
  37. </xsl:when>
  38. <xsl:otherwise>
  39. <fo:footnote>
  40. <fo:inline>
  41. <xsl:call-template name="format.footnote.mark">
  42. <xsl:with-param name="mark">
  43. <xsl:apply-templates select="." mode="footnote.number"/>
  44. </xsl:with-param>
  45. </xsl:call-template>
  46. </fo:inline>
  47. <fo:footnote-body xsl:use-attribute-sets="footnote.properties">
  48. <xsl:apply-templates/>
  49. </fo:footnote-body>
  50. </fo:footnote>
  51. </xsl:otherwise>
  52. </xsl:choose>
  53. </xsl:template>
  54. <xsl:template match="footnoteref">
  55. <xsl:variable name="footnote" select="key('id',@linkend)"/>
  56. <xsl:if test="not(local-name($footnote) = 'footnote')">
  57. <xsl:message terminate="yes">
  58. ERROR: A footnoteref element has a linkend that points to an element that is not a footnote.
  59. Typically this happens when an id attribute is accidentally applied to the child of a footnote element.
  60. target element: <xsl:value-of select="local-name($footnote)"/>
  61. linkend/id: <xsl:value-of select="@linkend"/>
  62. </xsl:message>
  63. </xsl:if>
  64. <xsl:call-template name="format.footnote.mark">
  65. <xsl:with-param name="mark">
  66. <xsl:apply-templates select="$footnote" mode="footnote.number"/>
  67. </xsl:with-param>
  68. </xsl:call-template>
  69. </xsl:template>
  70. <xsl:template match="footnote" mode="footnote.number">
  71. <xsl:choose>
  72. <xsl:when test="string-length(@label) != 0">
  73. <xsl:value-of select="@label"/>
  74. </xsl:when>
  75. <xsl:when test="ancestor::table or ancestor::informaltable">
  76. <xsl:variable name="tfnum">
  77. <xsl:number level="any" from="table|informaltable" format="1"/>
  78. </xsl:variable>
  79. <xsl:choose>
  80. <xsl:when test="string-length($table.footnote.number.symbols) &gt;= $tfnum">
  81. <xsl:value-of select="substring($table.footnote.number.symbols, $tfnum, 1)"/>
  82. </xsl:when>
  83. <xsl:otherwise>
  84. <xsl:number level="any" from="table|informaltable"
  85. format="{$table.footnote.number.format}"/>
  86. </xsl:otherwise>
  87. </xsl:choose>
  88. </xsl:when>
  89. <xsl:otherwise>
  90. <xsl:variable name="fnum">
  91. <!-- * Determine the footnote number to display for this footnote, -->
  92. <!-- * by counting all foonotes, ulinks, and any elements that have -->
  93. <!-- * an xlink:href attribute that meets the following criteria: -->
  94. <!-- * -->
  95. <!-- * - the content of the element is not a URI that is the same -->
  96. <!-- * URI as the value of the href attribute -->
  97. <!-- * - the href attribute is not an internal ID reference (does -->
  98. <!-- * not start with a hash sign) -->
  99. <!-- * - the href is not part of an olink reference (the element -->
  100. <!-- * - does not have an xlink:role attribute that indicates it is -->
  101. <!-- * an olink, and the hrf does not contain a hash sign) -->
  102. <!-- * - the element either has no xlink:type attribute or has -->
  103. <!-- * an xlink:type attribute whose value is 'simple' -->
  104. <!-- * -->
  105. <!-- * Note that hyperlinks are counted only if both the value of -->
  106. <!-- * ulink.footnotes is non-zero and the value of ulink.show is -->
  107. <!-- * non-zero -->
  108. <!-- FIXME: list in @from is probably not complete -->
  109. <xsl:number level="any"
  110. from="chapter|appendix|preface|article|refentry|bibliography"
  111. count="footnote[not(@label)][not(ancestor::table) and not(ancestor::informaltable)]
  112. |ulink[$ulink.footnotes != 0][node()][@url != .][not(ancestor::footnote)][$ulink.show != 0]
  113. |*[node()][@xlink:href][not(@xlink:href = .)][not(starts-with(@xlink:href,'#'))]
  114. [not(contains(@xlink:href,'#') and @xlink:role = $xolink.role)]
  115. [not(@xlink:type) or @xlink:type='simple']
  116. [not(ancestor::footnote)][$ulink.footnotes != 0][$ulink.show != 0]
  117. "
  118. format="1"/>
  119. </xsl:variable>
  120. <xsl:choose>
  121. <xsl:when test="string-length($footnote.number.symbols) &gt;= $fnum">
  122. <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
  123. </xsl:when>
  124. <xsl:otherwise>
  125. <xsl:number value="$fnum" format="{$footnote.number.format}"/>
  126. </xsl:otherwise>
  127. </xsl:choose>
  128. </xsl:otherwise>
  129. </xsl:choose>
  130. </xsl:template>
  131. <!-- ==================================================================== -->
  132. <xsl:template match="*" mode="footnote.body.number">
  133. <xsl:variable name="footnote.mark">
  134. <xsl:call-template name="format.footnote.mark">
  135. <xsl:with-param name="mark">
  136. <xsl:apply-templates select="ancestor::footnote" mode="footnote.number"/>
  137. </xsl:with-param>
  138. </xsl:call-template>
  139. </xsl:variable>
  140. <xsl:variable name="fo">
  141. <xsl:apply-templates select="."/>
  142. </xsl:variable>
  143. <xsl:variable name="fo-nodes" select="exsl:node-set($fo)"/>
  144. <xsl:choose>
  145. <xsl:when test="$fo-nodes//fo:block">
  146. <xsl:apply-templates select="$fo-nodes" mode="insert.fo.fnum">
  147. <xsl:with-param name="mark" select="$footnote.mark"/>
  148. </xsl:apply-templates>
  149. </xsl:when>
  150. <xsl:otherwise>
  151. <xsl:apply-templates select="$fo-nodes" mode="insert.fo.text">
  152. <xsl:with-param name="mark" select="$footnote.mark"/>
  153. </xsl:apply-templates>
  154. </xsl:otherwise>
  155. </xsl:choose>
  156. </xsl:template>
  157. <!-- ==================================================================== -->
  158. <xsl:template match="footnote/para[1]
  159. |footnote/simpara[1]
  160. |footnote/formalpara[1]"
  161. priority="2">
  162. <!-- this only works if the first thing in a footnote is a para, -->
  163. <!-- which is ok, because it usually is. -->
  164. <fo:block>
  165. <xsl:call-template name="format.footnote.mark">
  166. <xsl:with-param name="mark">
  167. <xsl:apply-templates select="ancestor::footnote" mode="footnote.number"/>
  168. </xsl:with-param>
  169. </xsl:call-template>
  170. <xsl:apply-templates/>
  171. </fo:block>
  172. </xsl:template>
  173. <xsl:template match="footnote" mode="table.footnote.mode">
  174. <xsl:choose>
  175. <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
  176. <fo:block xsl:use-attribute-sets="table.footnote.properties">
  177. <xsl:apply-templates/>
  178. </fo:block>
  179. </xsl:when>
  180. <xsl:when test="$exsl.node.set.available != 0">
  181. <fo:block xsl:use-attribute-sets="table.footnote.properties">
  182. <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
  183. <xsl:apply-templates select="*[position() &gt; 1]"/>
  184. </fo:block>
  185. </xsl:when>
  186. <xsl:otherwise>
  187. <xsl:message>
  188. <xsl:text>Warning: footnote number may not be generated </xsl:text>
  189. <xsl:text>correctly; </xsl:text>
  190. <xsl:value-of select="local-name(*[1])"/>
  191. <xsl:text> unexpected as first child of footnote.</xsl:text>
  192. </xsl:message>
  193. <fo:block xsl:use-attribute-sets="table.footnote.properties">
  194. <xsl:apply-templates/>
  195. </fo:block>
  196. </xsl:otherwise>
  197. </xsl:choose>
  198. </xsl:template>
  199. </xsl:stylesheet>