bookmarks.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.
  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-index="http://www.idiominc.com/opentopic/index"
  33. xmlns:opentopic-func="http://www.idiominc.com/opentopic/exsl/function"
  34. xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder"
  35. exclude-result-prefixes="xs opentopic-index opentopic opentopic-func ot-placeholder"
  36. version="2.0">
  37. <!-- Determines whether letter headings in an index generate bookmarks.
  38. 0 = no bookmarks.
  39. Any other number = if total # of terms exceeds $bookmarks.index-group-size, generate headers.
  40. To always generate headers, set to 1. -->
  41. <xsl:param name="bookmarks.index-group-size" as="xs:integer">100</xsl:param>
  42. <xsl:variable name="map" select="//opentopic:map"/>
  43. <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="bookmark">
  44. <xsl:variable name="mapTopicref" select="key('map-id', @id)[1]"/>
  45. <xsl:variable name="topicTitle">
  46. <xsl:call-template name="getNavTitle"/>
  47. </xsl:variable>
  48. <xsl:choose>
  49. <xsl:when test="$mapTopicref[@toc = 'yes' or not(@toc)] or
  50. not($mapTopicref)">
  51. <fo:bookmark>
  52. <xsl:attribute name="internal-destination">
  53. <xsl:call-template name="generate-toc-id"/>
  54. </xsl:attribute>
  55. <xsl:if test="$bookmarkStyle!='EXPANDED'">
  56. <xsl:attribute name="starting-state">hide</xsl:attribute>
  57. </xsl:if>
  58. <fo:bookmark-title>
  59. <xsl:value-of select="normalize-space($topicTitle)"/>
  60. </fo:bookmark-title>
  61. <xsl:apply-templates mode="bookmark"/>
  62. </fo:bookmark>
  63. </xsl:when>
  64. <xsl:otherwise>
  65. <xsl:apply-templates mode="bookmark"/>
  66. </xsl:otherwise>
  67. </xsl:choose>
  68. </xsl:template>
  69. <xsl:template match="*" mode="bookmark">
  70. <xsl:apply-templates mode="bookmark"/>
  71. </xsl:template>
  72. <xsl:template match="text()" mode="bookmark"/>
  73. <xsl:template name="createBookmarks">
  74. <xsl:variable name="bookmarks" as="element()*">
  75. <xsl:choose>
  76. <xsl:when test="$retain-bookmap-order">
  77. <xsl:apply-templates select="/" mode="bookmark"/>
  78. </xsl:when>
  79. <xsl:otherwise>
  80. <xsl:for-each select="/*/*[contains(@class, ' topic/topic ')]">
  81. <xsl:variable name="topicType">
  82. <xsl:call-template name="determineTopicType"/>
  83. </xsl:variable>
  84. <xsl:if test="$topicType = 'topicNotices'">
  85. <xsl:apply-templates select="." mode="bookmark"/>
  86. </xsl:if>
  87. </xsl:for-each>
  88. <xsl:choose>
  89. <xsl:when test="$map//*[contains(@class,' bookmap/toc ')][@href]"/>
  90. <xsl:when test="$map//*[contains(@class,' bookmap/toc ')]
  91. | /*[contains(@class,' map/map ')][not(contains(@class,' bookmap/bookmap '))]">
  92. <fo:bookmark internal-destination="{$id.toc}">
  93. <fo:bookmark-title>
  94. <xsl:call-template name="getVariable">
  95. <xsl:with-param name="id" select="'Table of Contents'"/>
  96. </xsl:call-template>
  97. </fo:bookmark-title>
  98. </fo:bookmark>
  99. </xsl:when>
  100. </xsl:choose>
  101. <xsl:for-each select="/*/*[contains(@class, ' topic/topic ')] |
  102. /*/ot-placeholder:glossarylist |
  103. /*/ot-placeholder:tablelist |
  104. /*/ot-placeholder:figurelist">
  105. <xsl:variable name="topicType">
  106. <xsl:call-template name="determineTopicType"/>
  107. </xsl:variable>
  108. <xsl:if test="not($topicType = 'topicNotices')">
  109. <xsl:apply-templates select="." mode="bookmark"/>
  110. </xsl:if>
  111. </xsl:for-each>
  112. <xsl:apply-templates select="/*" mode="bookmark-index"/>
  113. </xsl:otherwise>
  114. </xsl:choose>
  115. </xsl:variable>
  116. <xsl:if test="exists($bookmarks)">
  117. <fo:bookmark-tree>
  118. <xsl:copy-of select="$bookmarks"/>
  119. </fo:bookmark-tree>
  120. </xsl:if>
  121. </xsl:template>
  122. <xsl:template match="ot-placeholder:toc[$retain-bookmap-order]" mode="bookmark">
  123. <fo:bookmark internal-destination="{$id.toc}">
  124. <xsl:if test="$bookmarkStyle!='EXPANDED'">
  125. <xsl:attribute name="starting-state">hide</xsl:attribute>
  126. </xsl:if>
  127. <fo:bookmark-title>
  128. <xsl:call-template name="getVariable">
  129. <xsl:with-param name="id" select="'Table of Contents'"/>
  130. </xsl:call-template>
  131. </fo:bookmark-title>
  132. </fo:bookmark>
  133. </xsl:template>
  134. <xsl:template match="ot-placeholder:indexlist[$retain-bookmap-order]" mode="bookmark">
  135. <fo:bookmark internal-destination="{$id.index}">
  136. <xsl:if test="$bookmarkStyle!='EXPANDED'">
  137. <xsl:attribute name="starting-state">hide</xsl:attribute>
  138. </xsl:if>
  139. <fo:bookmark-title>
  140. <xsl:call-template name="getVariable">
  141. <xsl:with-param name="id" select="'Index'"/>
  142. </xsl:call-template>
  143. </fo:bookmark-title>
  144. </fo:bookmark>
  145. </xsl:template>
  146. <xsl:template match="ot-placeholder:glossarylist" mode="bookmark">
  147. <fo:bookmark internal-destination="{$id.glossary}">
  148. <xsl:if test="$bookmarkStyle!='EXPANDED'">
  149. <xsl:attribute name="starting-state">hide</xsl:attribute>
  150. </xsl:if>
  151. <fo:bookmark-title>
  152. <xsl:call-template name="getVariable">
  153. <xsl:with-param name="id" select="'Glossary'"/>
  154. </xsl:call-template>
  155. </fo:bookmark-title>
  156. <xsl:apply-templates mode="bookmark"/>
  157. </fo:bookmark>
  158. </xsl:template>
  159. <xsl:template match="ot-placeholder:tablelist" mode="bookmark">
  160. <xsl:if test="//*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ' )]">
  161. <fo:bookmark internal-destination="{$id.lot}">
  162. <xsl:if test="$bookmarkStyle!='EXPANDED'">
  163. <xsl:attribute name="starting-state">hide</xsl:attribute>
  164. </xsl:if>
  165. <fo:bookmark-title>
  166. <xsl:call-template name="getVariable">
  167. <xsl:with-param name="id" select="'List of Tables'"/>
  168. </xsl:call-template>
  169. </fo:bookmark-title>
  170. <xsl:apply-templates mode="bookmark"/>
  171. </fo:bookmark>
  172. </xsl:if>
  173. </xsl:template>
  174. <xsl:template match="ot-placeholder:figurelist" mode="bookmark">
  175. <xsl:if test="//*[contains(@class, ' topic/fig ')]/*[contains(@class, ' topic/title ' )]">
  176. <fo:bookmark internal-destination="{$id.lof}">
  177. <xsl:if test="$bookmarkStyle!='EXPANDED'">
  178. <xsl:attribute name="starting-state">hide</xsl:attribute>
  179. </xsl:if>
  180. <fo:bookmark-title>
  181. <xsl:call-template name="getVariable">
  182. <xsl:with-param name="id" select="'List of Figures'"/>
  183. </xsl:call-template>
  184. </fo:bookmark-title>
  185. <xsl:apply-templates mode="bookmark"/>
  186. </fo:bookmark>
  187. </xsl:if>
  188. </xsl:template>
  189. <xsl:template match="*" mode="bookmark-index">
  190. <xsl:if test="//opentopic-index:index.groups//opentopic-index:index.entry">
  191. <xsl:choose>
  192. <xsl:when test="$map//*[contains(@class,' bookmap/indexlist ')][@href]"/>
  193. <xsl:when test="$map//*[contains(@class,' bookmap/indexlist ')]
  194. | /*[contains(@class,' map/map ')][not(contains(@class,' bookmap/bookmap '))]">
  195. <fo:bookmark internal-destination="{$id.index}" starting-state="hide">
  196. <fo:bookmark-title>
  197. <xsl:call-template name="getVariable">
  198. <xsl:with-param name="id" select="'Index'"/>
  199. </xsl:call-template>
  200. </fo:bookmark-title>
  201. <xsl:if test="$bookmarks.index-group-size !=0 and
  202. count(//opentopic-index:index.groups//opentopic-index:index.entry) &gt; $bookmarks.index-group-size">
  203. <xsl:apply-templates select="//opentopic-index:index.groups" mode="bookmark-index"/>
  204. </xsl:if>
  205. </fo:bookmark>
  206. </xsl:when>
  207. </xsl:choose>
  208. </xsl:if>
  209. </xsl:template>
  210. <xsl:template match="opentopic-index:index.groups" mode="bookmark-index">
  211. <xsl:apply-templates select="opentopic-index:index.group" mode="bookmark-index"/>
  212. </xsl:template>
  213. <xsl:template match="opentopic-index:index.group" mode="bookmark-index">
  214. <xsl:apply-templates select="opentopic-index:label" mode="bookmark-index"/>
  215. </xsl:template>
  216. <xsl:template match="opentopic-index:label" mode="bookmark-index">
  217. <!-- Letter headings in index are always collapsed, regardless of bookmarkStyle. -->
  218. <fo:bookmark internal-destination="{generate-id(.)}" starting-state="hide">
  219. <fo:bookmark-title>
  220. <xsl:value-of select="."/>
  221. </fo:bookmark-title>
  222. </fo:bookmark>
  223. </xsl:template>
  224. </xsl:stylesheet>