footnote.xsl 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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:exsl="http://exslt.org/common"
  5. exclude-result-prefixes="exsl"
  6. version='1.0'>
  7. <!-- ********************************************************************
  8. $Id$
  9. ********************************************************************
  10. This file is part of the XSL DocBook Stylesheet distribution.
  11. See ../README or http://docbook.sf.net/release/xsl/current/ for
  12. copyright and other information.
  13. ******************************************************************** -->
  14. <xsl:template name="format.footnote.mark">
  15. <xsl:param name="mark" select="'?'"/>
  16. <fo:inline xsl:use-attribute-sets="footnote.mark.properties">
  17. <xsl:choose>
  18. <xsl:when test="$fop.extensions != 0">
  19. <xsl:attribute name="vertical-align">super</xsl:attribute>
  20. </xsl:when>
  21. <xsl:otherwise>
  22. <xsl:attribute name="baseline-shift">super</xsl:attribute>
  23. </xsl:otherwise>
  24. </xsl:choose>
  25. <xsl:copy-of select="$mark"/>
  26. </fo:inline>
  27. </xsl:template>
  28. <xsl:template match="footnote">
  29. <xsl:choose>
  30. <xsl:when test="ancestor::table or ancestor::informaltable">
  31. <xsl:call-template name="format.footnote.mark">
  32. <xsl:with-param name="mark">
  33. <xsl:apply-templates select="." mode="footnote.number"/>
  34. </xsl:with-param>
  35. </xsl:call-template>
  36. </xsl:when>
  37. <xsl:otherwise>
  38. <fo:footnote>
  39. <fo:inline>
  40. <xsl:call-template name="format.footnote.mark">
  41. <xsl:with-param name="mark">
  42. <xsl:apply-templates select="." mode="footnote.number"/>
  43. </xsl:with-param>
  44. </xsl:call-template>
  45. </fo:inline>
  46. <fo:footnote-body xsl:use-attribute-sets="footnote.properties">
  47. <xsl:apply-templates/>
  48. </fo:footnote-body>
  49. </fo:footnote>
  50. </xsl:otherwise>
  51. </xsl:choose>
  52. </xsl:template>
  53. <xsl:template match="footnoteref">
  54. <xsl:variable name="footnote" select="key('id',@linkend)"/>
  55. <xsl:call-template name="format.footnote.mark">
  56. <xsl:with-param name="mark">
  57. <xsl:apply-templates select="$footnote" mode="footnote.number"/>
  58. </xsl:with-param>
  59. </xsl:call-template>
  60. </xsl:template>
  61. <xsl:template match="footnote" mode="footnote.number">
  62. <xsl:choose>
  63. <xsl:when test="string-length(@label) != 0">
  64. <xsl:value-of select="@label"/>
  65. </xsl:when>
  66. <xsl:when test="ancestor::table or ancestor::informaltable">
  67. <xsl:variable name="tfnum">
  68. <xsl:number level="any" from="table|informaltable" format="1"/>
  69. </xsl:variable>
  70. <xsl:choose>
  71. <xsl:when test="string-length($table.footnote.number.symbols) &gt;= $tfnum">
  72. <xsl:value-of select="substring($table.footnote.number.symbols, $tfnum, 1)"/>
  73. </xsl:when>
  74. <xsl:otherwise>
  75. <xsl:number level="any" from="table|informaltable"
  76. format="{$table.footnote.number.format}"/>
  77. </xsl:otherwise>
  78. </xsl:choose>
  79. </xsl:when>
  80. <xsl:otherwise>
  81. <xsl:variable name="fnum">
  82. <!-- FIXME: list in @from is probably not complete -->
  83. <xsl:number level="any"
  84. from="chapter|appendix|preface|article|refentry|bibliography"
  85. count="footnote[not(@label)][not(ancestor::table) and not(ancestor::informaltable)]|ulink[$ulink.footnotes != 0][node()][@url != .][not(ancestor::footnote)][$ulink.show != 0]"
  86. format="1"/>
  87. </xsl:variable>
  88. <xsl:choose>
  89. <xsl:when test="string-length($footnote.number.symbols) &gt;= $fnum">
  90. <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
  91. </xsl:when>
  92. <xsl:otherwise>
  93. <xsl:number value="$fnum" format="{$footnote.number.format}"/>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </xsl:template>
  99. <!-- ==================================================================== -->
  100. <xsl:template match="*" mode="footnote.body.number">
  101. <xsl:variable name="footnote.mark">
  102. <xsl:call-template name="format.footnote.mark">
  103. <xsl:with-param name="mark">
  104. <xsl:apply-templates select="ancestor::footnote" mode="footnote.number"/>
  105. </xsl:with-param>
  106. </xsl:call-template>
  107. </xsl:variable>
  108. <xsl:variable name="fo">
  109. <xsl:apply-templates select="."/>
  110. </xsl:variable>
  111. <xsl:variable name="fo-nodes" select="exsl:node-set($fo)"/>
  112. <xsl:choose>
  113. <xsl:when test="$fo-nodes//fo:block">
  114. <xsl:apply-templates select="$fo-nodes" mode="insert.fo.fnum">
  115. <xsl:with-param name="mark" select="$footnote.mark"/>
  116. </xsl:apply-templates>
  117. </xsl:when>
  118. <xsl:otherwise>
  119. <xsl:apply-templates select="$fo-nodes" mode="insert.fo.text">
  120. <xsl:with-param name="mark" select="$footnote.mark"/>
  121. </xsl:apply-templates>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. </xsl:template>
  125. <!-- ==================================================================== -->
  126. <xsl:template match="footnote/para[1]
  127. |footnote/simpara[1]
  128. |footnote/formalpara[1]"
  129. priority="2">
  130. <!-- this only works if the first thing in a footnote is a para, -->
  131. <!-- which is ok, because it usually is. -->
  132. <fo:block>
  133. <xsl:call-template name="format.footnote.mark">
  134. <xsl:with-param name="mark">
  135. <xsl:apply-templates select="ancestor::footnote" mode="footnote.number"/>
  136. </xsl:with-param>
  137. </xsl:call-template>
  138. <xsl:apply-templates/>
  139. </fo:block>
  140. </xsl:template>
  141. <xsl:template match="footnote" mode="table.footnote.mode">
  142. <xsl:choose>
  143. <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
  144. <fo:block xsl:use-attribute-sets="table.footnote.properties">
  145. <xsl:apply-templates/>
  146. </fo:block>
  147. </xsl:when>
  148. <xsl:when test="function-available('exsl:node-set')">
  149. <fo:block xsl:use-attribute-sets="table.footnote.properties">
  150. <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
  151. <xsl:apply-templates select="*[position() &gt; 1]"/>
  152. </fo:block>
  153. </xsl:when>
  154. <xsl:otherwise>
  155. <xsl:message>
  156. <xsl:text>Warning: footnote number may not be generated </xsl:text>
  157. <xsl:text>correctly; </xsl:text>
  158. <xsl:value-of select="local-name(*[1])"/>
  159. <xsl:text> unexpected as first child of footnote.</xsl:text>
  160. </xsl:message>
  161. <fo:block xsl:use-attribute-sets="table.footnote.properties">
  162. <xsl:apply-templates/>
  163. </fo:block>
  164. </xsl:otherwise>
  165. </xsl:choose>
  166. </xsl:template>
  167. </xsl:stylesheet>