dita2odt-map.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!-- This file is part of the DITA Open Toolkit project.
  3. See the accompanying license.txt file for applicable licenses. -->
  4. <!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->
  5. <xsl:stylesheet
  6. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  8. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  9. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  10. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  11. xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  12. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  13. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
  14. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  15. xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
  16. xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  17. xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  18. xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  19. xmlns:math="http://www.w3.org/1998/Math/MathML"
  20. xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  21. xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  22. xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms"
  23. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  24. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  25. xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
  26. xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
  27. xmlns:prodtools="http://www.ibm.com/xmlns/prodtools"
  28. xmlns:opentopic="http://www.idiominc.com/opentopic"
  29. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  30. version="2.0"
  31. xmlns:related-links="http://dita-ot.sourceforge.net/ns/200709/related-links"
  32. exclude-result-prefixes="related-links dita-ot opentopic">
  33. <xsl:output method="xml"/>
  34. <xsl:output indent="yes"/>
  35. <xsl:strip-space elements="*"/>
  36. <xsl:variable name="mapType">
  37. <xsl:choose>
  38. <xsl:when test="/*[contains(@class, ' map/map ') and contains(@class, ' bookmap/bookmap ')]">
  39. <xsl:value-of select="'bookmap'"/>
  40. </xsl:when>
  41. <xsl:when test="/*[contains(@class, ' map/map ')]">
  42. <xsl:value-of select="'ditamap'"/>
  43. </xsl:when>
  44. <xsl:otherwise>
  45. <xsl:value-of select="'topic'"/>
  46. </xsl:otherwise>
  47. </xsl:choose>
  48. </xsl:variable>
  49. <xsl:variable name="map" select="//opentopic:map"/>
  50. <xsl:variable name="topicNumbers">
  51. <xsl:for-each select="//*[contains(@class, ' topic/topic ') and not(contains(@class, ' bkinfo/bkinfo '))]">
  52. <topic id="{@id}" guid="{generate-id()}"/>
  53. </xsl:for-each>
  54. </xsl:variable>
  55. <xsl:variable name="relatedTopicrefs" select="//*[contains(@class, ' map/reltable ')]//*[contains(@class, ' map/topicref ')]"/>
  56. <xsl:template name="create_toc">
  57. <text:table-of-content text:style-name="Sect1" text:protected="true" text:name="Table of Contents1">
  58. <text:table-of-content-source text:outline-level="10" text:use-index-marks="false" text:use-index-source-styles="true">
  59. <text:index-title-template text:style-name="Contents_20_Heading_TOC">Table of
  60. Contents</text:index-title-template>
  61. <text:table-of-content-entry-template text:outline-level="1" text:style-name="Contents_20_1_a">
  62. <text:index-entry-link-start/>
  63. <text:index-entry-chapter/>
  64. <text:index-entry-text/>
  65. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  66. <text:index-entry-page-number/>
  67. <text:index-entry-link-end/>
  68. </text:table-of-content-entry-template>
  69. <text:table-of-content-entry-template text:outline-level="2" text:style-name="Contents_20_2_a">
  70. <text:index-entry-link-start/>
  71. <text:index-entry-chapter/>
  72. <text:index-entry-text/>
  73. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  74. <text:index-entry-page-number/>
  75. <text:index-entry-link-end/>
  76. </text:table-of-content-entry-template>
  77. <text:table-of-content-entry-template text:outline-level="3" text:style-name="Contents_20_3_a">
  78. <text:index-entry-link-start/>
  79. <text:index-entry-chapter/>
  80. <text:index-entry-text/>
  81. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  82. <text:index-entry-page-number/>
  83. <text:index-entry-link-end/>
  84. </text:table-of-content-entry-template>
  85. <text:table-of-content-entry-template text:outline-level="4" text:style-name="Contents_20_4_a">
  86. <text:index-entry-link-start/>
  87. <text:index-entry-chapter/>
  88. <text:index-entry-span> </text:index-entry-span>
  89. <text:index-entry-text/>
  90. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  91. <text:index-entry-page-number/>
  92. <text:index-entry-link-end/>
  93. </text:table-of-content-entry-template>
  94. <text:table-of-content-entry-template text:outline-level="5" text:style-name="Contents_20_5_a">
  95. <text:index-entry-link-start/>
  96. <text:index-entry-chapter/>
  97. <text:index-entry-span> </text:index-entry-span>
  98. <text:index-entry-text/>
  99. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  100. <text:index-entry-page-number/>
  101. <text:index-entry-link-end/>
  102. </text:table-of-content-entry-template>
  103. <text:table-of-content-entry-template text:outline-level="6" text:style-name="Contents_20_6_a">
  104. <text:index-entry-link-start/>
  105. <text:index-entry-chapter/>
  106. <text:index-entry-span> </text:index-entry-span>
  107. <text:index-entry-text/>
  108. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  109. <text:index-entry-page-number/>
  110. <text:index-entry-link-end/>
  111. </text:table-of-content-entry-template>
  112. <text:table-of-content-entry-template text:outline-level="7" text:style-name="Contents_20_7_a">
  113. <text:index-entry-link-start/>
  114. <text:index-entry-chapter/>
  115. <text:index-entry-span> </text:index-entry-span>
  116. <text:index-entry-text/>
  117. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  118. <text:index-entry-page-number/>
  119. <text:index-entry-link-end/>
  120. </text:table-of-content-entry-template>
  121. <text:table-of-content-entry-template text:outline-level="8" text:style-name="Contents_20_8_a">
  122. <text:index-entry-link-start/>
  123. <text:index-entry-chapter/>
  124. <text:index-entry-span> </text:index-entry-span>
  125. <text:index-entry-text/>
  126. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  127. <text:index-entry-page-number/>
  128. <text:index-entry-link-end/>
  129. </text:table-of-content-entry-template>
  130. <text:table-of-content-entry-template text:outline-level="9" text:style-name="Contents_20_9_a">
  131. <text:index-entry-link-start/>
  132. <text:index-entry-chapter/>
  133. <text:index-entry-span> </text:index-entry-span>
  134. <text:index-entry-text/>
  135. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  136. <text:index-entry-page-number/>
  137. <text:index-entry-link-end/>
  138. </text:table-of-content-entry-template>
  139. <text:table-of-content-entry-template text:outline-level="10" text:style-name="Contents_20_10_a">
  140. <text:index-entry-link-start/>
  141. <text:index-entry-chapter/>
  142. <text:index-entry-span> </text:index-entry-span>
  143. <text:index-entry-text/>
  144. <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
  145. <text:index-entry-page-number/>
  146. <text:index-entry-link-end/>
  147. </text:table-of-content-entry-template>
  148. <text:index-source-styles text:outline-level="1">
  149. <text:index-source-style text:style-name="Appendix_20_Heading"/>
  150. </text:index-source-styles>
  151. </text:table-of-content-source>
  152. <text:index-body>
  153. <text:index-title text:style-name="Sect1" text:name="Table of Contents1_Head">
  154. <text:p text:style-name="Contents_20_Heading">Table of Contents</text:p>
  155. </text:index-title>
  156. <xsl:choose>
  157. <xsl:when test="$map and not($map = '')">
  158. <xsl:apply-templates select="$map/child::*[contains(@class, ' map/topicref ')]" mode="toc"/>
  159. </xsl:when>
  160. <xsl:otherwise>
  161. <xsl:apply-templates select="child::*[contains(@class, ' topic/topic ')]" mode="toc"/>
  162. </xsl:otherwise>
  163. </xsl:choose>
  164. </text:index-body>
  165. </text:table-of-content>
  166. <!-- page break. -->
  167. <text:p text:style-name="PB"/>
  168. </xsl:template>
  169. <!-- compress the opentopic:map tag since it has alreay been parsed for creating toc -->
  170. <xsl:template match="opentopic:map"/>
  171. <xsl:template match="*[contains(@class, ' map/topicref ')]" mode="toc">
  172. <xsl:if test="@href">
  173. <!-- topicref depth -->
  174. <xsl:variable name="depth" select="count(ancestor-or-self::*[contains(@class, ' map/topicref ')])"/>
  175. <!-- navtitle value -->
  176. <xsl:variable name="navtitle">
  177. <!--
  178. <xsl:value-of select="child::*[contains(@class, ' map/topicmeta ')]/child::*[contains(@class, ' topic/navtitle ')]"/>
  179. -->
  180. <xsl:apply-templates select="child::*[contains(@class, ' map/topicmeta ')]/child::*[contains(@class, ' topic/navtitle ')]" mode="dita-ot:text-only"/>
  181. </xsl:variable>
  182. <!-- href value -->
  183. <xsl:variable name="href" select="@href"/>
  184. <xsl:variable name="level">
  185. <xsl:choose>
  186. <xsl:when test="$depth &gt; 10">
  187. <xsl:value-of select="10"/>
  188. </xsl:when>
  189. <xsl:otherwise>
  190. <xsl:value-of select="$depth"/>
  191. </xsl:otherwise>
  192. </xsl:choose>
  193. </xsl:variable>
  194. <text:p text:style-name="{concat('P', $level)}">
  195. <text:a xlink:type="simple" text:style-name="underline_none" xlink:href="{concat($href, '')}">
  196. <xsl:value-of select="$navtitle"/>
  197. <text:tab/>
  198. <text:bookmark-ref text:reference-format="page" text:ref-name="{substring-after($href, '#')}">
  199. </text:bookmark-ref>
  200. </text:a>
  201. </text:p>
  202. </xsl:if>
  203. <xsl:apply-templates select="child::*[contains(@class, ' map/topicref ')]" mode="toc"/>
  204. </xsl:template>
  205. <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="toc">
  206. <xsl:if test="*[contains(@class, ' topic/title ')]">
  207. <!-- topic depth -->
  208. <xsl:variable name="depth" select="count(ancestor-or-self::*[contains(@class, ' topic/topic ')])"/>
  209. <!-- title value -->
  210. <xsl:variable name="title">
  211. <!--
  212. <xsl:value-of select="child::*[contains(@class, ' topic/title ')]"/>
  213. -->
  214. <xsl:apply-templates select="child::*[contains(@class, ' topic/title ')]" mode="dita-ot:text-only"/>
  215. </xsl:variable>
  216. <!-- href value -->
  217. <xsl:variable name="href" select="concat('#', @id)"/>
  218. <xsl:variable name="level">
  219. <xsl:choose>
  220. <xsl:when test="$depth &gt; 10">
  221. <xsl:value-of select="10"/>
  222. </xsl:when>
  223. <xsl:otherwise>
  224. <xsl:value-of select="$depth"/>
  225. </xsl:otherwise>
  226. </xsl:choose>
  227. </xsl:variable>
  228. <text:p text:style-name="{concat('P', $level)}">
  229. <text:a xlink:type="simple" text:style-name="underline_none" xlink:href="{concat($href, '')}">
  230. <xsl:value-of select="$title"/>
  231. <text:tab/>
  232. <text:bookmark-ref text:reference-format="page" text:ref-name="{substring-after($href, '#')}">
  233. </text:bookmark-ref>
  234. </text:a>
  235. </text:p>
  236. </xsl:if>
  237. <xsl:apply-templates select="child::*[contains(@class, ' topic/topic ')]" mode="toc"/>
  238. </xsl:template>
  239. <!-- create map title -->
  240. <xsl:template name="create_map_title">
  241. <xsl:apply-templates
  242. select="($map/*[contains(@class, ' topic/title ')],
  243. /*/@title,
  244. //opentopic:map/*[contains(@class, ' map/topicref ')][1]
  245. /*[contains(@class, ' map/topicmeta ')]
  246. /*[contains(@class, ' topic/navtitle ')])[1]"
  247. mode="create_title"/>
  248. </xsl:template>
  249. <!-- create topic title -->
  250. <xsl:template name="create_topic_title">
  251. <xsl:apply-templates select="/*[contains(@class, ' topic/topic ')][1]/*[contains(@class, ' topic/title ')]" mode="create_title"/>
  252. </xsl:template>
  253. <xsl:template match="*[contains(@class, ' topic/title ')] | @title | *[contains(@class, ' topic/navtitle ')]" mode="create_title">
  254. <text:p text:style-name="Title">
  255. <xsl:apply-templates select="." mode="dita-ot:text-only"/>
  256. </text:p>
  257. <!-- page break. -->
  258. <text:p text:style-name="PB"/>
  259. </xsl:template>
  260. <!-- create book title -->
  261. <xsl:template name="create_book_title">
  262. <xsl:apply-templates select="//opentopic:map/*[contains(@class, ' bookmap/booktitle ')]" mode="create_book_title"/>
  263. </xsl:template>
  264. <xsl:template match="*[contains(@class, ' bookmap/booktitle ')]" mode="create_book_title">
  265. <text:p text:style-name="Title">
  266. <xsl:apply-templates select="*[contains(@class, ' bookmap/booklibrary ')]" mode="dita-ot:text-only"/>
  267. <text:line-break/>
  268. <xsl:apply-templates select="*[contains(@class, ' bookmap/mainbooktitle ')]" mode="dita-ot:text-only"/>
  269. <text:line-break/>
  270. <xsl:apply-templates select="*[contains(@class, ' bookmap/booktitlealt ')]" mode="dita-ot:text-only"/>
  271. </text:p>
  272. <!-- page break. -->
  273. <text:p text:style-name="PB"/>
  274. </xsl:template>
  275. <xsl:template name="create_book_abstract">
  276. <xsl:apply-templates select="*[contains(@class, ' bookmap/bookmap ')]
  277. /*[contains(@class, ' topic/topic ')]" mode="create_book_abstract"/>
  278. </xsl:template>
  279. <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="create_book_abstract">
  280. <xsl:variable name="topicType">
  281. <xsl:call-template name="determineTopicType"/>
  282. </xsl:variable>
  283. <xsl:if test="$topicType = 'topicAbstract'">
  284. <xsl:apply-templates/>
  285. </xsl:if>
  286. </xsl:template>
  287. <xsl:template name="create_book_notices">
  288. <xsl:apply-templates select="*[contains(@class, ' bookmap/bookmap ')]
  289. /*[contains(@class, ' topic/topic ')]" mode="create_book_notices"/>
  290. </xsl:template>
  291. <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="create_book_notices">
  292. <xsl:variable name="topicType">
  293. <xsl:call-template name="determineTopicType"/>
  294. </xsl:variable>
  295. <xsl:if test="$topicType = 'topicNotices'">
  296. <xsl:apply-templates/>
  297. </xsl:if>
  298. </xsl:template>
  299. </xsl:stylesheet>