toc.xsl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. 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. <!-- ==================================================================== -->
  13. <!-- FIXME: in the contexts where <toc> can occur, I think it's always
  14. the case that a page-sequence is required. Is that true? -->
  15. <xsl:template match="toc">
  16. <xsl:variable name="master-reference">
  17. <xsl:call-template name="select.pagemaster"/>
  18. </xsl:variable>
  19. <xsl:choose>
  20. <xsl:when test="*">
  21. <xsl:if test="$process.source.toc != 0">
  22. <!-- if the toc isn't empty, process it -->
  23. <fo:page-sequence hyphenate="{$hyphenate}"
  24. master-reference="{$master-reference}">
  25. <xsl:attribute name="language">
  26. <xsl:call-template name="l10n.language"/>
  27. </xsl:attribute>
  28. <xsl:attribute name="format">
  29. <xsl:call-template name="page.number.format">
  30. <xsl:with-param name="element" select="'toc'"/>
  31. <xsl:with-param name="master-reference"
  32. select="$master-reference"/>
  33. </xsl:call-template>
  34. </xsl:attribute>
  35. <xsl:attribute name="initial-page-number">
  36. <xsl:call-template name="initial.page.number">
  37. <xsl:with-param name="element" select="'toc'"/>
  38. <xsl:with-param name="master-reference"
  39. select="$master-reference"/>
  40. </xsl:call-template>
  41. </xsl:attribute>
  42. <xsl:attribute name="force-page-count">
  43. <xsl:call-template name="force.page.count">
  44. <xsl:with-param name="master-reference"
  45. select="$master-reference"/>
  46. </xsl:call-template>
  47. </xsl:attribute>
  48. <xsl:attribute name="hyphenation-character">
  49. <xsl:call-template name="gentext">
  50. <xsl:with-param name="key" select="'hyphenation-character'"/>
  51. </xsl:call-template>
  52. </xsl:attribute>
  53. <xsl:attribute name="hyphenation-push-character-count">
  54. <xsl:call-template name="gentext">
  55. <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
  56. </xsl:call-template>
  57. </xsl:attribute>
  58. <xsl:attribute name="hyphenation-remain-character-count">
  59. <xsl:call-template name="gentext">
  60. <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
  61. </xsl:call-template>
  62. </xsl:attribute>
  63. <xsl:apply-templates select="." mode="running.head.mode">
  64. <xsl:with-param name="master-reference" select="$master-reference"/>
  65. </xsl:apply-templates>
  66. <xsl:apply-templates select="." mode="running.foot.mode">
  67. <xsl:with-param name="master-reference" select="$master-reference"/>
  68. </xsl:apply-templates>
  69. <fo:flow flow-name="xsl-region-body">
  70. <xsl:call-template name="set.flow.properties">
  71. <xsl:with-param name="element" select="local-name(.)"/>
  72. <xsl:with-param name="master-reference"
  73. select="$master-reference"/>
  74. </xsl:call-template>
  75. <fo:block xsl:use-attribute-sets="toc.margin.properties">
  76. <xsl:call-template name="table.of.contents.titlepage"/>
  77. <xsl:apply-templates/>
  78. </fo:block>
  79. </fo:flow>
  80. </fo:page-sequence>
  81. </xsl:if>
  82. </xsl:when>
  83. <xsl:otherwise>
  84. <xsl:if test="$process.empty.source.toc != 0">
  85. <fo:page-sequence hyphenate="{$hyphenate}"
  86. master-reference="{$master-reference}">
  87. <xsl:attribute name="language">
  88. <xsl:call-template name="l10n.language"/>
  89. </xsl:attribute>
  90. <xsl:attribute name="format">
  91. <xsl:call-template name="page.number.format">
  92. <xsl:with-param name="element" select="'toc'"/>
  93. <xsl:with-param name="master-reference"
  94. select="$master-reference"/>
  95. </xsl:call-template>
  96. </xsl:attribute>
  97. <xsl:attribute name="initial-page-number">
  98. <xsl:call-template name="initial.page.number">
  99. <xsl:with-param name="element" select="'toc'"/>
  100. <xsl:with-param name="master-reference"
  101. select="$master-reference"/>
  102. </xsl:call-template>
  103. </xsl:attribute>
  104. <xsl:attribute name="hyphenation-character">
  105. <xsl:call-template name="gentext">
  106. <xsl:with-param name="key" select="'hyphenation-character'"/>
  107. </xsl:call-template>
  108. </xsl:attribute>
  109. <xsl:attribute name="hyphenation-push-character-count">
  110. <xsl:call-template name="gentext">
  111. <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
  112. </xsl:call-template>
  113. </xsl:attribute>
  114. <xsl:attribute name="hyphenation-remain-character-count">
  115. <xsl:call-template name="gentext">
  116. <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
  117. </xsl:call-template>
  118. </xsl:attribute>
  119. <xsl:apply-templates select="." mode="running.head.mode">
  120. <xsl:with-param name="master-reference" select="$master-reference"/>
  121. </xsl:apply-templates>
  122. <xsl:apply-templates select="." mode="running.foot.mode">
  123. <xsl:with-param name="master-reference" select="$master-reference"/>
  124. </xsl:apply-templates>
  125. <fo:flow flow-name="xsl-region-body">
  126. <xsl:choose>
  127. <xsl:when test="parent::section
  128. or parent::sect1
  129. or parent::sect2
  130. or parent::sect3
  131. or parent::sect4
  132. or parent::sect5">
  133. <xsl:apply-templates select="parent::*"
  134. mode="toc.for.section"/>
  135. </xsl:when>
  136. <xsl:when test="parent::article">
  137. <xsl:apply-templates select="parent::*"
  138. mode="toc.for.component"/>
  139. </xsl:when>
  140. <xsl:when test="parent::book
  141. or parent::part">
  142. <xsl:apply-templates select="parent::*"
  143. mode="toc.for.division"/>
  144. </xsl:when>
  145. <xsl:when test="parent::set">
  146. <xsl:apply-templates select="parent::*"
  147. mode="toc.for.set"/>
  148. </xsl:when>
  149. <!-- there aren't any other contexts that allow toc -->
  150. <xsl:otherwise>
  151. <xsl:message>
  152. <xsl:text>I don't know how to make a TOC in this context!</xsl:text>
  153. </xsl:message>
  154. </xsl:otherwise>
  155. </xsl:choose>
  156. </fo:flow>
  157. </fo:page-sequence>
  158. </xsl:if>
  159. </xsl:otherwise>
  160. </xsl:choose>
  161. </xsl:template>
  162. <xsl:template match="tocpart|tocchap
  163. |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
  164. <xsl:apply-templates select="tocentry"/>
  165. <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
  166. <fo:block start-indent="{count(ancestor::*)*2}pc">
  167. <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
  168. </fo:block>
  169. </xsl:if>
  170. </xsl:template>
  171. <xsl:template match="tocentry|tocfront|tocback">
  172. <fo:block text-align-last="justify"
  173. end-indent="2pc"
  174. last-line-end-indent="-2pc">
  175. <fo:inline keep-with-next.within-line="always">
  176. <xsl:choose>
  177. <xsl:when test="@linkend">
  178. <fo:basic-link internal-destination="{@linkend}">
  179. <xsl:apply-templates/>
  180. </fo:basic-link>
  181. </xsl:when>
  182. <xsl:otherwise>
  183. <xsl:apply-templates/>
  184. </xsl:otherwise>
  185. </xsl:choose>
  186. </fo:inline>
  187. <xsl:choose>
  188. <xsl:when test="@linkend">
  189. <fo:inline keep-together.within-line="always">
  190. <xsl:text> </xsl:text>
  191. <fo:leader leader-pattern="dots"
  192. keep-with-next.within-line="always"/>
  193. <xsl:text> </xsl:text>
  194. <fo:basic-link internal-destination="{@linkend}">
  195. <xsl:choose>
  196. <xsl:when test="@pagenum">
  197. <xsl:value-of select="@pagenum"/>
  198. </xsl:when>
  199. <xsl:otherwise>
  200. <fo:page-number-citation ref-id="{@linkend}"/>
  201. </xsl:otherwise>
  202. </xsl:choose>
  203. </fo:basic-link>
  204. </fo:inline>
  205. </xsl:when>
  206. <xsl:when test="@pagenum">
  207. <fo:inline keep-together.within-line="always">
  208. <xsl:text> </xsl:text>
  209. <fo:leader leader-pattern="dots"
  210. keep-with-next.within-line="always"/>
  211. <xsl:text> </xsl:text>
  212. <xsl:value-of select="@pagenum"/>
  213. </fo:inline>
  214. </xsl:when>
  215. <xsl:otherwise>
  216. <!-- just the leaders, what else can I do? -->
  217. <fo:inline keep-together.within-line="always">
  218. <xsl:text> </xsl:text>
  219. <fo:leader leader-pattern="space"
  220. keep-with-next.within-line="always"/>
  221. </fo:inline>
  222. </xsl:otherwise>
  223. </xsl:choose>
  224. </fo:block>
  225. </xsl:template>
  226. <!-- ==================================================================== -->
  227. <xsl:template match="*" mode="toc.for.section">
  228. <!--
  229. <xsl:call-template name="section.toc"/>
  230. -->
  231. </xsl:template>
  232. <xsl:template match="*" mode="toc.for.component">
  233. <xsl:call-template name="component.toc"/>
  234. </xsl:template>
  235. <xsl:template match="*" mode="toc.for.section">
  236. <!--
  237. <xsl:call-template name="section.toc"/>
  238. -->
  239. </xsl:template>
  240. <xsl:template match="*" mode="toc.for.division">
  241. <xsl:call-template name="division.toc"/>
  242. </xsl:template>
  243. <xsl:template match="*" mode="toc.for.set">
  244. <!--
  245. <xsl:call-template name="set.toc"/>
  246. -->
  247. </xsl:template>
  248. <!-- ==================================================================== -->
  249. <xsl:template match="lot|lotentry">
  250. </xsl:template>
  251. </xsl:stylesheet>