root-processing.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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.
  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-i18n="http://www.idiominc.com/opentopic/i18n"
  32. xmlns:opentopic-index="http://www.idiominc.com/opentopic/index"
  33. xmlns:opentopic="http://www.idiominc.com/opentopic"
  34. xmlns:opentopic-func="http://www.idiominc.com/opentopic/exsl/function"
  35. xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder"
  36. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  37. exclude-result-prefixes="opentopic-index opentopic opentopic-i18n opentopic-func dita-ot xs ot-placeholder"
  38. version="2.0">
  39. <xsl:param name="bookmap-order" select="'discard'" as="xs:string"/>
  40. <xsl:variable name="retain-bookmap-order" select="*[contains(@class,' bookmap/bookmap ')] and $bookmap-order eq 'retain'" as="xs:boolean"/>
  41. <xsl:variable name="writing-mode" as="xs:string">
  42. <xsl:variable name="lang" select="if (contains($locale, '_')) then substring-before($locale, '_') else $locale"/>
  43. <xsl:choose>
  44. <xsl:when test="some $l in ('ar', 'fa', 'he', 'ps', 'ur') satisfies $l eq $lang">rl</xsl:when>
  45. <xsl:otherwise>lr</xsl:otherwise>
  46. </xsl:choose>
  47. </xsl:variable>
  48. <xsl:variable name="mapType" as="xs:string">
  49. <xsl:choose>
  50. <xsl:when test="/*[contains(@class, ' bookmap/bookmap ')]">bookmap</xsl:when>
  51. <xsl:otherwise>ditamap</xsl:otherwise>
  52. </xsl:choose>
  53. </xsl:variable>
  54. <xsl:variable name="productName">
  55. <xsl:variable name="mapProdname" select="(/*/opentopic:map//*[contains(@class, ' topic/prodname ')])[1]" as="element()?"/>
  56. <xsl:choose>
  57. <xsl:when test="$mapProdname">
  58. <xsl:value-of select="$mapProdname"/>
  59. </xsl:when>
  60. <xsl:otherwise>
  61. <xsl:call-template name="getVariable">
  62. <xsl:with-param name="id" select="'Product Name'"/>
  63. </xsl:call-template>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:variable>
  67. <xsl:variable name="map" select="//opentopic:map" as="element()?"/>
  68. <xsl:variable name="topicNumbers">
  69. <xsl:for-each select="//*[contains(@class, ' topic/topic ')]">
  70. <topic guid="{generate-id()}">
  71. <xsl:call-template name="commonattributes"/>
  72. </topic>
  73. </xsl:for-each>
  74. </xsl:variable>
  75. <xsl:variable name="relatedTopicrefs" select="//*[contains(@class, ' map/reltable ')]//*[contains(@class, ' map/topicref ')]" as="element()*"/>
  76. <xsl:template name="validateTopicRefs">
  77. <xsl:apply-templates select="//opentopic:map" mode="topicref-validation"/>
  78. </xsl:template>
  79. <xsl:template match="opentopic:map" mode="topicref-validation">
  80. <xsl:apply-templates mode="topicref-validation"/>
  81. </xsl:template>
  82. <xsl:template match="*[contains(@class, ' map/topicref ')]" mode="topicref-validation">
  83. <xsl:if test="@href = ''">
  84. <xsl:call-template name="output-message">
  85. <xsl:with-param name="id" select="'PDFX004F'"/>
  86. </xsl:call-template>
  87. </xsl:if>
  88. <xsl:if test="@href and @id">
  89. <xsl:if test="not(@id = '') and empty(key('topic-id', @id))">
  90. <xsl:call-template name="output-message">
  91. <xsl:with-param name="id" select="'PDFX005F'"/>
  92. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/></xsl:with-param>
  93. </xsl:call-template>
  94. </xsl:if>
  95. </xsl:if>
  96. <xsl:apply-templates mode="topicref-validation"/>
  97. </xsl:template>
  98. <xsl:template match="*" mode="topicref-validation"/>
  99. <xsl:template name="createMetadata">
  100. <!-- Override in XSL processor specific stylesheets -->
  101. </xsl:template>
  102. <xsl:template match="/" mode="dita-ot:title-metadata" as="xs:string?">
  103. <xsl:choose>
  104. <xsl:when test="exists($map/*[contains(@class, ' bookmap/booktitle ')]/*[contains(@class,' bookmap/mainbooktitle ')])">
  105. <xsl:value-of>
  106. <xsl:apply-templates select="$map/*[contains(@class, ' bookmap/booktitle ')]/*[contains(@class,' bookmap/mainbooktitle ')][1]" mode="dita-ot:text-only"/>
  107. </xsl:value-of>
  108. </xsl:when>
  109. <xsl:when test="exists($map/*[contains(@class,' topic/title ')])">
  110. <xsl:value-of>
  111. <xsl:apply-templates select="$map/*[contains(@class,' topic/title ')][1]" mode="dita-ot:text-only"/>
  112. </xsl:value-of>
  113. </xsl:when>
  114. <xsl:when test="exists(//*[contains(@class, ' map/map ')]/@title)">
  115. <xsl:value-of select="//*[contains(@class, ' map/map ')]/@title"/>
  116. </xsl:when>
  117. <xsl:otherwise>
  118. <xsl:value-of>
  119. <xsl:apply-templates select="descendant::*[contains(@class, ' topic/topic ')][1]/*[contains(@class, ' topic/title ')]" mode="dita-ot:text-only"/>
  120. </xsl:value-of>
  121. </xsl:otherwise>
  122. </xsl:choose>
  123. </xsl:template>
  124. <xsl:template match="/" mode="dita-ot:author-metadata" as="xs:string?">
  125. <xsl:variable name="authorinformation" select="$map/*[contains(@class, ' bookmap/bookmeta ')]/*[contains(@class, ' xnal-d/authorinformation ')]" as="element()*"/>
  126. <xsl:choose>
  127. <xsl:when test="exists($authorinformation/descendant::*[contains(@class, ' xnal-d/personname ')])">
  128. <xsl:for-each select="$authorinformation/descendant::*[contains(@class, ' xnal-d/personname ')][1]">
  129. <!-- Requires locale specific processing -->
  130. <xsl:value-of>
  131. <xsl:apply-templates select="*[contains(@class, ' xnal-d/firstname ')]/node()" mode="dita-ot:text-only"/>
  132. <xsl:text> </xsl:text>
  133. <xsl:apply-templates select="*[contains(@class, ' xnal-d/lastname ')]/node()" mode="dita-ot:text-only"/>
  134. </xsl:value-of>
  135. </xsl:for-each>
  136. </xsl:when>
  137. <xsl:when test="exists($authorinformation/descendant::*[contains(@class, ' xnal-d/organizationname ')])">
  138. <xsl:value-of>
  139. <xsl:apply-templates select="$authorinformation/descendant::*[contains(@class, ' xnal-d/organizationname ')]" mode="dita-ot:text-only"/>
  140. </xsl:value-of>
  141. </xsl:when>
  142. <xsl:when test="exists($map/*[contains(@class, ' bookmap/bookmeta ')]/*[contains(@class, ' topic/author ')])">
  143. <xsl:value-of>
  144. <xsl:apply-templates select="$map/*[contains(@class, ' bookmap/bookmeta ')]/*[contains(@class, ' topic/author ')]" mode="dita-ot:text-only"/>
  145. </xsl:value-of>
  146. </xsl:when>
  147. </xsl:choose>
  148. </xsl:template>
  149. <xsl:template match="/" mode="dita-ot:keywords-metadata" as="xs:string*">
  150. <xsl:variable name="keywords" select="$map/*[contains(@class, ' bookmap/bookmeta ')]/*[contains(@class, ' topic/keywords ')]/*[contains(@class, 'topic/keyword ')]" as="element()*"/>
  151. <xsl:for-each select="$keywords">
  152. <xsl:value-of>
  153. <xsl:apply-templates select="." mode="dita-ot:text-only"/>
  154. </xsl:value-of>
  155. </xsl:for-each>
  156. </xsl:template>
  157. <xsl:template match="/" mode="dita-ot:subject-metadata" as="xs:string?">
  158. <xsl:choose>
  159. <xsl:when test="exists($map/*[contains(@class, ' bookmap/bookmeta ')]/*[contains(@class, ' map/shortdesc ')])">
  160. <xsl:value-of>
  161. <xsl:apply-templates select="$map/*[contains(@class, ' bookmap/bookmeta ')]/*[contains(@class, ' map/shortdesc ')]" mode="dita-ot:text-only"/>
  162. </xsl:value-of>
  163. </xsl:when>
  164. <xsl:when test="exists($map/*[contains(@class, ' topic/shortdesc ')])">
  165. <xsl:value-of>
  166. <xsl:apply-templates select="$map/*[contains(@class, ' topic/shortdesc ')]" mode="dita-ot:text-only"/>
  167. </xsl:value-of>
  168. </xsl:when>
  169. </xsl:choose>
  170. </xsl:template>
  171. <xsl:template match="/" name="rootTemplate">
  172. <xsl:call-template name="validateTopicRefs"/>
  173. <fo:root xsl:use-attribute-sets="__fo__root">
  174. <xsl:call-template name="createMetadata"/>
  175. <xsl:call-template name="createLayoutMasters"/>
  176. <xsl:call-template name="createBookmarks"/>
  177. <xsl:apply-templates select="*" mode="generatePageSequences"/>
  178. </fo:root>
  179. </xsl:template>
  180. <xsl:variable name="map-based-page-sequence-generation" select="true()" as="xs:boolean"/>
  181. <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="generatePageSequences">
  182. <fo:page-sequence master-reference="ditamap-body-sequence" xsl:use-attribute-sets="page-sequence.body">
  183. <xsl:call-template name="startPageNumbering"/>
  184. <xsl:call-template name="insertBodyStaticContents"/>
  185. <fo:flow flow-name="xsl-region-body">
  186. <xsl:apply-templates select="." mode="processTopic"/>
  187. </fo:flow>
  188. </fo:page-sequence>
  189. </xsl:template>
  190. <xsl:template match="*[contains(@class, ' map/map ')]" mode="generatePageSequences">
  191. <xsl:call-template name="createFrontMatter"/>
  192. <xsl:call-template name="createToc"/>
  193. <xsl:choose>
  194. <xsl:when test="$map-based-page-sequence-generation">
  195. <fo:page-sequence master-reference="ditamap-body-sequence" xsl:use-attribute-sets="page-sequence.body">
  196. <xsl:call-template name="startPageNumbering"/>
  197. <xsl:call-template name="insertBodyStaticContents"/>
  198. <fo:flow flow-name="xsl-region-body">
  199. <xsl:for-each select="opentopic:map/*[contains(@class, ' map/topicref ')]">
  200. <xsl:for-each select="key('topic-id', @id)">
  201. <xsl:apply-templates select="." mode="processTopic"/>
  202. </xsl:for-each>
  203. </xsl:for-each>
  204. </fo:flow>
  205. </fo:page-sequence>
  206. <xsl:call-template name="createIndex"/>
  207. </xsl:when>
  208. <!-- legacy topic based page-sequence generation -->
  209. <xsl:otherwise>
  210. <xsl:apply-templates/>
  211. </xsl:otherwise>
  212. </xsl:choose>
  213. <xsl:call-template name="createBackCover"/>
  214. </xsl:template>
  215. <xsl:template match="*[contains(@class, ' bookmap/bookmap ')]" mode="generatePageSequences" priority="10">
  216. <xsl:call-template name="createFrontMatter"/>
  217. <xsl:choose>
  218. <xsl:when test="$map-based-page-sequence-generation">
  219. <xsl:apply-templates select="opentopic:map/*[contains(@class, ' map/topicref ')]" mode="generatePageSequences"/>
  220. </xsl:when>
  221. <!-- legacy topic based page-sequence generation -->
  222. <xsl:otherwise>
  223. <xsl:if test="not($retain-bookmap-order)">
  224. <xsl:apply-templates select="/bookmap/*[contains(@class,' topic/topic ')]" mode="process-notices"/>
  225. <xsl:call-template name="createToc"/>
  226. </xsl:if>
  227. <xsl:apply-templates/>
  228. <xsl:if test="not($retain-bookmap-order)">
  229. <xsl:call-template name="createIndex"/>
  230. </xsl:if>
  231. </xsl:otherwise>
  232. </xsl:choose>
  233. <xsl:call-template name="createBackCover"/>
  234. </xsl:template>
  235. <xsl:template match="*" mode="generatePageSequences" priority="-1">
  236. <xsl:apply-templates select="*" mode="generatePageSequences"/>
  237. </xsl:template>
  238. <xsl:template match="*[contains(@class, ' map/topicref ')]" mode="generatePageSequences" priority="0">
  239. <xsl:choose>
  240. <xsl:when test="ancestor::*[contains(@class,' bookmap/frontmatter ')]">
  241. <!-- TODO: To fit the pattern, this should be in its own match template. But a general match for frontmatter/*
  242. conflicts with priority of existing rules (e.g., preface); changing priorities would
  243. break customizations. -->
  244. <xsl:for-each select="key('topic-id', @id)">
  245. <xsl:call-template name="processFrontMatterTopic"/>
  246. </xsl:for-each>
  247. </xsl:when>
  248. <xsl:otherwise>
  249. <xsl:for-each select="key('topic-id', @id)">
  250. <xsl:call-template name="processTopicSimple"/>
  251. </xsl:for-each>
  252. </xsl:otherwise>
  253. </xsl:choose>
  254. </xsl:template>
  255. <xsl:template match="*[contains(@class, ' bookmap/frontmatter ') or
  256. contains(@class, ' bookmap/backmatter ') or
  257. contains(@class, ' bookmap/booklists ')]" mode="generatePageSequences">
  258. <xsl:apply-templates select="*" mode="generatePageSequences"/>
  259. </xsl:template>
  260. <xsl:template match="*[contains(@class, ' bookmap/chapter ')]" mode="generatePageSequences">
  261. <xsl:for-each select="key('topic-id', @id)">
  262. <xsl:call-template name="processTopicChapter"/>
  263. </xsl:for-each>
  264. </xsl:template>
  265. <xsl:template match="*[contains(@class, ' bookmap/appendix ')]" mode="generatePageSequences">
  266. <xsl:for-each select="key('topic-id', @id)">
  267. <xsl:call-template name="processTopicAppendix"/>
  268. </xsl:for-each>
  269. </xsl:template>
  270. <xsl:template match="*[contains(@class, ' bookmap/preface ')]" mode="generatePageSequences">
  271. <xsl:for-each select="key('topic-id', @id)">
  272. <xsl:call-template name="processTopicPreface"/>
  273. </xsl:for-each>
  274. </xsl:template>
  275. <xsl:template match="*[contains(@class, ' bookmap/appendices ')]" mode="generatePageSequences">
  276. <xsl:for-each select="key('topic-id', @id)">
  277. <xsl:call-template name="processTopicAppendices"/>
  278. </xsl:for-each>
  279. </xsl:template>
  280. <xsl:template match="*[contains(@class, ' bookmap/part ')]" mode="generatePageSequences">
  281. <xsl:for-each select="key('topic-id', @id)">
  282. <xsl:call-template name="processTopicPart"/>
  283. </xsl:for-each>
  284. </xsl:template>
  285. <xsl:template match="*[contains(@class, ' bookmap/figurelist ')]" mode="generatePageSequences">
  286. <xsl:for-each select="key('topic-id', @id)">
  287. <xsl:choose>
  288. <xsl:when test="self::ot-placeholder:figurelist">
  289. <xsl:call-template name="createFigureList"/>
  290. </xsl:when>
  291. <xsl:otherwise>
  292. <xsl:call-template name="processTopicSimple"/>
  293. </xsl:otherwise>
  294. </xsl:choose>
  295. </xsl:for-each>
  296. </xsl:template>
  297. <xsl:template match="*[contains(@class, ' bookmap/tablelist ')]" mode="generatePageSequences">
  298. <xsl:for-each select="key('topic-id', @id)">
  299. <xsl:choose>
  300. <xsl:when test="self::ot-placeholder:tablelist">
  301. <xsl:call-template name="createTableList"/>
  302. </xsl:when>
  303. <xsl:otherwise>
  304. <xsl:call-template name="processTopicSimple"/>
  305. </xsl:otherwise>
  306. </xsl:choose>
  307. </xsl:for-each>
  308. </xsl:template>
  309. <xsl:template match="*[contains(@class, ' bookmap/indexlist ')]" mode="generatePageSequences">
  310. <xsl:for-each select="key('topic-id', @id)">
  311. <xsl:choose>
  312. <xsl:when test="self::ot-placeholder:indexlist">
  313. <xsl:call-template name="createIndex"/>
  314. </xsl:when>
  315. <xsl:otherwise>
  316. <xsl:call-template name="processIndexList"/>
  317. </xsl:otherwise>
  318. </xsl:choose>
  319. </xsl:for-each>
  320. </xsl:template>
  321. <xsl:template match="*[contains(@class, ' bookmap/toc ')]" mode="generatePageSequences">
  322. <xsl:for-each select="key('topic-id', @id)">
  323. <xsl:choose>
  324. <xsl:when test="self::ot-placeholder:toc">
  325. <xsl:call-template name="createToc"/>
  326. </xsl:when>
  327. <xsl:otherwise>
  328. <xsl:call-template name="processTocList"/>
  329. </xsl:otherwise>
  330. </xsl:choose>
  331. </xsl:for-each>
  332. </xsl:template>
  333. <xsl:template match="*[contains(@class, ' bookmap/glossarylist ')]" mode="generatePageSequences">
  334. <xsl:for-each select="key('topic-id', @id)">
  335. <xsl:choose>
  336. <xsl:when test="self::ot-placeholder:glossarylist">
  337. <xsl:call-template name="createGlossary"/>
  338. </xsl:when>
  339. <xsl:otherwise>
  340. <xsl:call-template name="processTopicSimple"/>
  341. </xsl:otherwise>
  342. </xsl:choose>
  343. </xsl:for-each>
  344. </xsl:template>
  345. <xsl:template match="*[contains(@class, ' bookmap/notices ')]" mode="generatePageSequences">
  346. <xsl:for-each select="key('topic-id', @id)">
  347. <xsl:call-template name="processTopicNotices"/>
  348. </xsl:for-each>
  349. </xsl:template>
  350. <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="process-notices">
  351. <xsl:variable name="topicType">
  352. <xsl:call-template name="determineTopicType"/>
  353. </xsl:variable>
  354. <xsl:if test="$topicType = 'topicNotices'">
  355. <xsl:call-template name="processTopicNotices"/>
  356. </xsl:if>
  357. </xsl:template>
  358. <xsl:template match="*[contains(@class, ' map/map ')]">
  359. <xsl:apply-templates/>
  360. </xsl:template>
  361. </xsl:stylesheet>