toc.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?xml version='1.0'?>
  2. <!--
  3. Copyright © 2004-2006 by Idiom Technologies, Inc. All rights reserved.
  4. IDIOM is a registered trademark of Idiom Technologies, Inc. and WORLDSERVER
  5. and WORLDSTART are trademarks of Idiom Technologies, Inc. All other
  6. trademarks are the property of their respective owners.
  7. IDIOM TECHNOLOGIES, INC. IS DELIVERING THE SOFTWARE "AS IS," WITH
  8. ABSOLUTELY NO WARRANTIES WHATSOEVER, WHETHER EXPRESS OR IMPLIED, AND IDIOM
  9. TECHNOLOGIES, INC. DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
  10. BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  11. PURPOSE AND WARRANTY OF NON-INFRINGEMENT. IDIOM TECHNOLOGIES, INC. SHALL NOT
  12. BE LIABLE FOR INDIRECT, INCIDENTAL, SPECIAL, COVER, PUNITIVE, EXEMPLARY,
  13. RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF
  14. ANTICIPATED PROFIT), ARISING FROM ANY CAUSE UNDER OR RELATED TO OR ARISING
  15. OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF IDIOM
  16. TECHNOLOGIES, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  17. Idiom Technologies, Inc. and its licensors shall not be liable for any
  18. damages suffered by any person as a result of using and/or modifying the
  19. Software or its derivatives. In no event shall Idiom Technologies, Inc.'s
  20. liability for any damages hereunder exceed the amounts received by Idiom
  21. Technologies, Inc. as a result of this transaction.
  22. These terms and conditions supersede the terms and conditions in any
  23. licensing agreement to the extent that such terms and conditions conflict
  24. with those set forth herein.
  25. This file is part of the DITA Open Toolkit project hosted on Sourceforge.net.
  26. See the accompanying license.txt file for applicable licenses.
  27. -->
  28. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  29. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  30. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  31. xmlns:opentopic="http://www.idiominc.com/opentopic"
  32. xmlns:opentopic-func="http://www.idiominc.com/opentopic/exsl/function"
  33. xmlns:opentopic-index="http://www.idiominc.com/opentopic/index"
  34. xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder"
  35. exclude-result-prefixes="xs opentopic opentopic-func ot-placeholder opentopic-index"
  36. version="2.0">
  37. <xsl:variable name="map" select="//opentopic:map"/>
  38. <xsl:template name="createTocHeader">
  39. <fo:block xsl:use-attribute-sets="__toc__header" id="{$id.toc}">
  40. <xsl:call-template name="getVariable">
  41. <xsl:with-param name="id" select="'Table of Contents'"/>
  42. </xsl:call-template>
  43. </fo:block>
  44. </xsl:template>
  45. <xsl:template match="/" mode="toc">
  46. <xsl:apply-templates mode="toc">
  47. <xsl:with-param name="include" select="'true'"/>
  48. </xsl:apply-templates>
  49. </xsl:template>
  50. <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="toc">
  51. <xsl:param name="include"/>
  52. <xsl:variable name="topicLevel" as="xs:integer">
  53. <xsl:apply-templates select="." mode="get-topic-level"/>
  54. </xsl:variable>
  55. <xsl:if test="$topicLevel &lt; $tocMaximumLevel">
  56. <xsl:variable name="mapTopicref" select="key('map-id', @id)[1]"/>
  57. <xsl:choose>
  58. <!-- In a future version, suppressing Notices in the TOC should not be hard-coded. -->
  59. <xsl:when test="$retain-bookmap-order and $mapTopicref/self::*[contains(@class, ' bookmap/notices ')]"/>
  60. <xsl:when test="$mapTopicref[@toc = 'yes' or not(@toc)] or
  61. (not($mapTopicref) and $include = 'true')">
  62. <fo:block xsl:use-attribute-sets="__toc__indent">
  63. <xsl:variable name="tocItemContent">
  64. <fo:basic-link xsl:use-attribute-sets="__toc__link">
  65. <xsl:attribute name="internal-destination">
  66. <xsl:call-template name="generate-toc-id"/>
  67. </xsl:attribute>
  68. <xsl:apply-templates select="$mapTopicref" mode="tocPrefix"/>
  69. <fo:inline xsl:use-attribute-sets="__toc__title">
  70. <xsl:call-template name="getNavTitle" />
  71. </fo:inline>
  72. <fo:inline xsl:use-attribute-sets="__toc__page-number">
  73. <fo:leader xsl:use-attribute-sets="__toc__leader"/>
  74. <fo:page-number-citation>
  75. <xsl:attribute name="ref-id">
  76. <xsl:call-template name="generate-toc-id"/>
  77. </xsl:attribute>
  78. </fo:page-number-citation>
  79. </fo:inline>
  80. </fo:basic-link>
  81. </xsl:variable>
  82. <xsl:choose>
  83. <xsl:when test="not($mapTopicref)">
  84. <xsl:apply-templates select="." mode="tocText">
  85. <xsl:with-param name="tocItemContent" select="$tocItemContent"/>
  86. <xsl:with-param name="currentNode" select="."/>
  87. </xsl:apply-templates>
  88. </xsl:when>
  89. <xsl:otherwise>
  90. <xsl:apply-templates select="$mapTopicref" mode="tocText">
  91. <xsl:with-param name="tocItemContent" select="$tocItemContent"/>
  92. <xsl:with-param name="currentNode" select="."/>
  93. </xsl:apply-templates>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </fo:block>
  97. <xsl:apply-templates mode="toc">
  98. <xsl:with-param name="include" select="'true'"/>
  99. </xsl:apply-templates>
  100. </xsl:when>
  101. <xsl:otherwise>
  102. <xsl:apply-templates mode="toc">
  103. <xsl:with-param name="include" select="'true'"/>
  104. </xsl:apply-templates>
  105. </xsl:otherwise>
  106. </xsl:choose>
  107. </xsl:if>
  108. </xsl:template>
  109. <xsl:template match="*[contains(@class, ' bookmap/chapter ')] |
  110. *[contains(@class, ' bookmap/bookmap ')]/opentopic:map/*[contains(@class, ' map/topicref ')]" mode="tocPrefix" priority="-1">
  111. <xsl:call-template name="getVariable">
  112. <xsl:with-param name="id" select="'Table of Contents Chapter'"/>
  113. <xsl:with-param name="params">
  114. <number>
  115. <xsl:apply-templates select="." mode="topicTitleNumber"/>
  116. </number>
  117. </xsl:with-param>
  118. </xsl:call-template>
  119. </xsl:template>
  120. <xsl:template match="*[contains(@class, ' bookmap/appendix ')]" mode="tocPrefix">
  121. <xsl:call-template name="getVariable">
  122. <xsl:with-param name="id" select="'Table of Contents Appendix'"/>
  123. <xsl:with-param name="params">
  124. <number>
  125. <xsl:apply-templates select="." mode="topicTitleNumber"/>
  126. </number>
  127. </xsl:with-param>
  128. </xsl:call-template>
  129. </xsl:template>
  130. <xsl:template match="*[contains(@class, ' bookmap/part ')]" mode="tocPrefix">
  131. <xsl:call-template name="getVariable">
  132. <xsl:with-param name="id" select="'Table of Contents Part'"/>
  133. <xsl:with-param name="params">
  134. <number>
  135. <xsl:apply-templates select="." mode="topicTitleNumber"/>
  136. </number>
  137. </xsl:with-param>
  138. </xsl:call-template>
  139. </xsl:template>
  140. <xsl:template match="*[contains(@class, ' bookmap/preface ')]" mode="tocPrefix">
  141. <xsl:call-template name="getVariable">
  142. <xsl:with-param name="id" select="'Table of Contents Preface'"/>
  143. </xsl:call-template>
  144. </xsl:template>
  145. <xsl:template match="*[contains(@class, ' bookmap/notices ')]" mode="tocPrefix">
  146. <xsl:call-template name="getVariable">
  147. <xsl:with-param name="id" select="'Table of Contents Notices'"/>
  148. </xsl:call-template>
  149. </xsl:template>
  150. <xsl:template match="node()" mode="tocPrefix" priority="-10"/>
  151. <xsl:template match="*[contains(@class, ' bookmap/chapter ')] |
  152. opentopic:map/*[contains(@class, ' map/topicref ')]" mode="tocText" priority="-1">
  153. <xsl:param name="tocItemContent"/>
  154. <xsl:param name="currentNode"/>
  155. <xsl:for-each select="$currentNode">
  156. <fo:block xsl:use-attribute-sets="__toc__chapter__content">
  157. <xsl:copy-of select="$tocItemContent"/>
  158. </fo:block>
  159. </xsl:for-each>
  160. </xsl:template>
  161. <xsl:template match="*[contains(@class, ' bookmap/appendix ')]" mode="tocText">
  162. <xsl:param name="tocItemContent"/>
  163. <xsl:param name="currentNode"/>
  164. <xsl:for-each select="$currentNode">
  165. <fo:block xsl:use-attribute-sets="__toc__appendix__content">
  166. <xsl:copy-of select="$tocItemContent"/>
  167. </fo:block>
  168. </xsl:for-each>
  169. </xsl:template>
  170. <xsl:template match="*[contains(@class, ' bookmap/part ')]" mode="tocText">
  171. <xsl:param name="tocItemContent"/>
  172. <xsl:param name="currentNode"/>
  173. <xsl:for-each select="$currentNode">
  174. <fo:block xsl:use-attribute-sets="__toc__part__content">
  175. <xsl:copy-of select="$tocItemContent"/>
  176. </fo:block>
  177. </xsl:for-each>
  178. </xsl:template>
  179. <xsl:template match="*[contains(@class, ' bookmap/preface ')]" mode="tocText">
  180. <xsl:param name="tocItemContent"/>
  181. <xsl:param name="currentNode"/>
  182. <xsl:for-each select="$currentNode">
  183. <fo:block xsl:use-attribute-sets="__toc__preface__content">
  184. <xsl:copy-of select="$tocItemContent"/>
  185. </fo:block>
  186. </xsl:for-each>
  187. </xsl:template>
  188. <xsl:template match="*[contains(@class, ' bookmap/notices ')]" mode="tocText">
  189. <xsl:param name="tocItemContent"/>
  190. <xsl:param name="currentNode"/>
  191. <xsl:for-each select="$currentNode">
  192. <fo:block xsl:use-attribute-sets="__toc__notices__content">
  193. <xsl:copy-of select="$tocItemContent"/>
  194. </fo:block>
  195. </xsl:for-each>
  196. </xsl:template>
  197. <xsl:template match="node()" mode="tocText" priority="-10">
  198. <xsl:param name="tocItemContent"/>
  199. <xsl:param name="currentNode"/>
  200. <xsl:for-each select="$currentNode">
  201. <fo:block xsl:use-attribute-sets="__toc__topic__content">
  202. <xsl:copy-of select="$tocItemContent"/>
  203. </fo:block>
  204. </xsl:for-each>
  205. </xsl:template>
  206. <xsl:template match="node()" mode="toc">
  207. <xsl:param name="include"/>
  208. <xsl:apply-templates mode="toc">
  209. <xsl:with-param name="include" select="$include"/>
  210. </xsl:apply-templates>
  211. </xsl:template>
  212. <xsl:template name="createToc">
  213. <xsl:if test="$generate-toc">
  214. <xsl:variable name="toc">
  215. <xsl:choose>
  216. <xsl:when test="$map//*[contains(@class,' bookmap/toc ')][@href]"/>
  217. <xsl:when test="$map//*[contains(@class,' bookmap/toc ')]">
  218. <xsl:apply-templates select="/" mode="toc"/>
  219. </xsl:when>
  220. <xsl:when test="/*[contains(@class,' map/map ')][not(contains(@class,' bookmap/bookmap '))]">
  221. <xsl:apply-templates select="/" mode="toc"/>
  222. <xsl:call-template name="toc.index"/>
  223. </xsl:when>
  224. </xsl:choose>
  225. </xsl:variable>
  226. <xsl:if test="count($toc/*) > 0">
  227. <fo:page-sequence master-reference="toc-sequence" xsl:use-attribute-sets="page-sequence.toc">
  228. <xsl:call-template name="insertTocStaticContents"/>
  229. <fo:flow flow-name="xsl-region-body">
  230. <xsl:call-template name="createTocHeader"/>
  231. <fo:block>
  232. <fo:marker marker-class-name="current-header">
  233. <xsl:call-template name="getVariable">
  234. <xsl:with-param name="id" select="'Table of Contents'"/>
  235. </xsl:call-template>
  236. </fo:marker>
  237. <xsl:copy-of select="$toc"/>
  238. </fo:block>
  239. </fo:flow>
  240. </fo:page-sequence>
  241. </xsl:if>
  242. </xsl:if>
  243. </xsl:template>
  244. <xsl:template name="processTocList">
  245. <fo:page-sequence master-reference="toc-sequence" xsl:use-attribute-sets="page-sequence.toc">
  246. <xsl:call-template name="insertTocStaticContents"/>
  247. <fo:flow flow-name="xsl-region-body">
  248. <xsl:call-template name="createTocHeader"/>
  249. <fo:block>
  250. <xsl:apply-templates/>
  251. </fo:block>
  252. </fo:flow>
  253. </fo:page-sequence>
  254. </xsl:template>
  255. <xsl:template match="ot-placeholder:toc[$retain-bookmap-order]">
  256. <xsl:call-template name="createToc"/>
  257. </xsl:template>
  258. <xsl:template match="ot-placeholder:indexlist" mode="toc" name="toc.index">
  259. <xsl:if test="(//opentopic-index:index.groups//opentopic-index:index.entry) and (exists($index-entries//opentopic-index:index.entry))">
  260. <fo:block xsl:use-attribute-sets="__toc__indent__booklist">
  261. <fo:block xsl:use-attribute-sets="__toc__topic__content__booklist">
  262. <fo:basic-link internal-destination="{$id.index}" xsl:use-attribute-sets="__toc__link">
  263. <fo:inline xsl:use-attribute-sets="__toc__title">
  264. <xsl:call-template name="getVariable">
  265. <xsl:with-param name="id" select="'Index'"/>
  266. </xsl:call-template>
  267. </fo:inline>
  268. <fo:inline xsl:use-attribute-sets="__toc__page-number">
  269. <fo:leader xsl:use-attribute-sets="__toc__leader"/>
  270. <fo:page-number-citation ref-id="{$id.index}"/>
  271. </fo:inline>
  272. </fo:basic-link>
  273. </fo:block>
  274. </fo:block>
  275. </xsl:if>
  276. </xsl:template>
  277. <xsl:template match="ot-placeholder:glossarylist" mode="toc">
  278. <fo:block xsl:use-attribute-sets="__toc__indent__glossary">
  279. <fo:block xsl:use-attribute-sets="__toc__topic__content__glossary">
  280. <fo:basic-link internal-destination="{$id.glossary}" xsl:use-attribute-sets="__toc__link">
  281. <fo:inline xsl:use-attribute-sets="__toc__title">
  282. <xsl:call-template name="getVariable">
  283. <xsl:with-param name="id" select="'Glossary'"/>
  284. </xsl:call-template>
  285. </fo:inline>
  286. <fo:inline xsl:use-attribute-sets="__toc__page-number">
  287. <fo:leader xsl:use-attribute-sets="__toc__leader"/>
  288. <fo:page-number-citation ref-id="{$id.glossary}"/>
  289. </fo:inline>
  290. </fo:basic-link>
  291. </fo:block>
  292. </fo:block>
  293. </xsl:template>
  294. <xsl:template match="ot-placeholder:tablelist" mode="toc">
  295. <xsl:if test="//*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ' )]">
  296. <fo:block xsl:use-attribute-sets="__toc__indent__lot">
  297. <fo:block xsl:use-attribute-sets="__toc__topic__content__lot">
  298. <fo:basic-link internal-destination="{$id.lot}" xsl:use-attribute-sets="__toc__link">
  299. <fo:inline xsl:use-attribute-sets="__toc__title">
  300. <xsl:call-template name="getVariable">
  301. <xsl:with-param name="id" select="'List of Tables'"/>
  302. </xsl:call-template>
  303. </fo:inline>
  304. <fo:inline xsl:use-attribute-sets="__toc__page-number">
  305. <fo:leader xsl:use-attribute-sets="__toc__leader"/>
  306. <fo:page-number-citation ref-id="{$id.lot}"/>
  307. </fo:inline>
  308. </fo:basic-link>
  309. </fo:block>
  310. </fo:block>
  311. </xsl:if>
  312. </xsl:template>
  313. <xsl:template match="ot-placeholder:figurelist" mode="toc">
  314. <xsl:if test="//*[contains(@class, ' topic/fig ')]/*[contains(@class, ' topic/title ' )]">
  315. <fo:block xsl:use-attribute-sets="__toc__indent__lof">
  316. <fo:block xsl:use-attribute-sets="__toc__topic__content__lof">
  317. <fo:basic-link internal-destination="{$id.lof}" xsl:use-attribute-sets="__toc__link">
  318. <fo:inline xsl:use-attribute-sets="__toc__title">
  319. <xsl:call-template name="getVariable">
  320. <xsl:with-param name="id" select="'List of Figures'"/>
  321. </xsl:call-template>
  322. </fo:inline>
  323. <fo:inline xsl:use-attribute-sets="__toc__page-number">
  324. <fo:leader xsl:use-attribute-sets="__toc__leader"/>
  325. <fo:page-number-citation ref-id="{$id.lof}"/>
  326. </fo:inline>
  327. </fo:basic-link>
  328. </fo:block>
  329. </fo:block>
  330. </xsl:if>
  331. </xsl:template>
  332. <xsl:template match="*[contains(@class, ' glossentry/glossentry ')]" mode="toc" priority="10"/>
  333. </xsl:stylesheet>