eclipse.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:ng="http://docbook.org/docbook-ng"
  4. xmlns:db="http://docbook.org/ns/docbook"
  5. xmlns:exsl="http://exslt.org/common"
  6. version="1.0"
  7. exclude-result-prefixes="exsl db ng">
  8. <xsl:import href="../html/chunk.xsl"/>
  9. <!-- ********************************************************************
  10. $Id: eclipse.xsl 9149 2011-11-12 00:12:07Z bobstayton $
  11. ********************************************************************
  12. This file is part of the XSL DocBook Stylesheet distribution.
  13. See ../README or http://docbook.sf.net/release/xsl/current/ for
  14. copyright and other information.
  15. ******************************************************************** -->
  16. <xsl:template match="/">
  17. <!-- * Get a title for current doc so that we let the user -->
  18. <!-- * know what document we are processing at this point. -->
  19. <xsl:variable name="doc.title">
  20. <xsl:call-template name="get.doc.title"/>
  21. </xsl:variable>
  22. <xsl:choose>
  23. <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
  24. toss the namespace and continue. Use the docbook5 namespaced
  25. stylesheets for DocBook5 if you don't want to use this feature.-->
  26. <!-- include extra test for Xalan quirk -->
  27. <xsl:when test="$exsl.node.set.available != 0
  28. and (*/self::ng:* or */self::db:*)">
  29. <xsl:call-template name="log.message">
  30. <xsl:with-param name="level">Note</xsl:with-param>
  31. <xsl:with-param name="source" select="$doc.title"/>
  32. <xsl:with-param name="context-desc">
  33. <xsl:text>namesp. cut</xsl:text>
  34. </xsl:with-param>
  35. <xsl:with-param name="message">
  36. <xsl:text>stripped namespace before processing</xsl:text>
  37. </xsl:with-param>
  38. </xsl:call-template>
  39. <xsl:variable name="nons">
  40. <xsl:apply-templates mode="stripNS"/>
  41. </xsl:variable>
  42. <xsl:call-template name="log.message">
  43. <xsl:with-param name="level">Note</xsl:with-param>
  44. <xsl:with-param name="source" select="$doc.title"/>
  45. <xsl:with-param name="context-desc">
  46. <xsl:text>namesp. cut</xsl:text>
  47. </xsl:with-param>
  48. <xsl:with-param name="message">
  49. <xsl:text>processing stripped document</xsl:text>
  50. </xsl:with-param>
  51. </xsl:call-template>
  52. <xsl:apply-templates select="exsl:node-set($nons)"/>
  53. </xsl:when>
  54. <xsl:otherwise>
  55. <xsl:choose>
  56. <xsl:when test="$rootid != ''">
  57. <xsl:choose>
  58. <xsl:when test="count(key('id',$rootid)) = 0">
  59. <xsl:message terminate="yes">
  60. <xsl:text>ID '</xsl:text>
  61. <xsl:value-of select="$rootid"/>
  62. <xsl:text>' not found in document.</xsl:text>
  63. </xsl:message>
  64. </xsl:when>
  65. <xsl:otherwise>
  66. <xsl:if test="$collect.xref.targets = 'yes' or
  67. $collect.xref.targets = 'only'">
  68. <xsl:apply-templates select="key('id', $rootid)"
  69. mode="collect.targets"/>
  70. </xsl:if>
  71. <xsl:if test="$collect.xref.targets != 'only'">
  72. <xsl:message>Formatting from <xsl:value-of
  73. select="$rootid"/></xsl:message>
  74. <xsl:apply-templates select="key('id',$rootid)"
  75. mode="process.root"/>
  76. <xsl:call-template name="etoc"/>
  77. <xsl:call-template name="plugin.xml"/>
  78. <xsl:call-template name="helpidx"/>
  79. </xsl:if>
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. </xsl:when>
  83. <xsl:otherwise>
  84. <xsl:if test="$collect.xref.targets = 'yes' or
  85. $collect.xref.targets = 'only'">
  86. <xsl:apply-templates select="/" mode="collect.targets"/>
  87. </xsl:if>
  88. <xsl:if test="$collect.xref.targets != 'only'">
  89. <xsl:apply-templates select="/" mode="process.root"/>
  90. <xsl:call-template name="etoc"/>
  91. <xsl:call-template name="plugin.xml"/>
  92. <xsl:call-template name="helpidx"/>
  93. </xsl:if>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </xsl:template>
  99. <xsl:template name="etoc">
  100. <xsl:call-template name="write.chunk">
  101. <xsl:with-param name="filename">
  102. <xsl:if test="$manifest.in.base.dir != 0">
  103. <xsl:value-of select="$chunk.base.dir"/>
  104. </xsl:if>
  105. <xsl:value-of select="'toc.xml'"/>
  106. </xsl:with-param>
  107. <xsl:with-param name="method" select="'xml'"/>
  108. <xsl:with-param name="encoding" select="'utf-8'"/>
  109. <xsl:with-param name="indent" select="'yes'"/>
  110. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  111. <xsl:with-param name="content">
  112. <xsl:choose>
  113. <xsl:when test="$rootid != ''">
  114. <xsl:variable name="title">
  115. <xsl:if test="$eclipse.autolabel=1">
  116. <xsl:variable name="label.markup">
  117. <xsl:apply-templates select="key('id',$rootid)" mode="label.markup"/>
  118. </xsl:variable>
  119. <xsl:if test="normalize-space($label.markup)">
  120. <xsl:value-of select="concat($label.markup,$autotoc.label.separator)"/>
  121. </xsl:if>
  122. </xsl:if>
  123. <xsl:apply-templates select="key('id',$rootid)" mode="title.markup"/>
  124. </xsl:variable>
  125. <xsl:variable name="href">
  126. <xsl:call-template name="href.target.with.base.dir">
  127. <xsl:with-param name="object" select="key('id',$rootid)"/>
  128. </xsl:call-template>
  129. </xsl:variable>
  130. <toc label="{normalize-space($title)}" topic="{$href}">
  131. <xsl:apply-templates select="key('id',$rootid)/*" mode="etoc"/>
  132. </toc>
  133. </xsl:when>
  134. <xsl:otherwise>
  135. <xsl:variable name="title">
  136. <xsl:if test="$eclipse.autolabel=1">
  137. <xsl:variable name="label.markup">
  138. <xsl:apply-templates select="/*" mode="label.markup"/>
  139. </xsl:variable>
  140. <xsl:if test="normalize-space($label.markup)">
  141. <xsl:value-of select="concat($label.markup,$autotoc.label.separator)"/>
  142. </xsl:if>
  143. </xsl:if>
  144. <xsl:apply-templates select="/*" mode="title.markup"/>
  145. </xsl:variable>
  146. <xsl:variable name="href">
  147. <xsl:call-template name="href.target.with.base.dir">
  148. <xsl:with-param name="object" select="/"/>
  149. </xsl:call-template>
  150. </xsl:variable>
  151. <toc label="{normalize-space($title)}" topic="{$href}">
  152. <xsl:apply-templates select="/*/*" mode="etoc"/>
  153. </toc>
  154. </xsl:otherwise>
  155. </xsl:choose>
  156. </xsl:with-param>
  157. </xsl:call-template>
  158. </xsl:template>
  159. <xsl:template match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" mode="etoc">
  160. <xsl:variable name="title">
  161. <xsl:if test="$eclipse.autolabel=1">
  162. <xsl:variable name="label.markup">
  163. <xsl:apply-templates select="." mode="label.markup"/>
  164. </xsl:variable>
  165. <xsl:if test="normalize-space($label.markup)">
  166. <xsl:value-of select="concat($label.markup,$autotoc.label.separator)"/>
  167. </xsl:if>
  168. </xsl:if>
  169. <xsl:apply-templates select="." mode="title.markup"/>
  170. </xsl:variable>
  171. <xsl:variable name="href">
  172. <xsl:call-template name="href.target.with.base.dir">
  173. <xsl:with-param name="context" select="/"/> <!-- Generate links relative to the location of root file/toc.xml file -->
  174. </xsl:call-template>
  175. </xsl:variable>
  176. <topic label="{normalize-space($title)}" href="{$href}">
  177. <xsl:apply-templates select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" mode="etoc"/>
  178. </topic>
  179. </xsl:template>
  180. <xsl:template match="text()" mode="etoc"/>
  181. <xsl:template name="plugin.xml">
  182. <xsl:call-template name="write.chunk">
  183. <xsl:with-param name="filename">
  184. <xsl:if test="$manifest.in.base.dir != 0">
  185. <xsl:value-of select="$chunk.base.dir"/>
  186. </xsl:if>
  187. <xsl:value-of select="'plugin.xml'"/>
  188. </xsl:with-param>
  189. <xsl:with-param name="method" select="'xml'"/>
  190. <xsl:with-param name="encoding" select="'utf-8'"/>
  191. <xsl:with-param name="indent" select="'yes'"/>
  192. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  193. <xsl:with-param name="content">
  194. <plugin name="{$eclipse.plugin.name}"
  195. id="{$eclipse.plugin.id}"
  196. version="1.0"
  197. provider-name="{$eclipse.plugin.provider}">
  198. <extension point="org.eclipse.help.toc">
  199. <toc file="toc.xml" primary="true"/>
  200. </extension>
  201. <extension point="org.eclipse.help.index">
  202. <index file="index.xml"/>
  203. </extension>
  204. </plugin>
  205. </xsl:with-param>
  206. </xsl:call-template>
  207. </xsl:template>
  208. <!-- ==================================================================== -->
  209. <!-- The following templates come from the javahelp xsls with modifications needed to make them generate and ecilpse index.xml file -->
  210. <xsl:template name="helpidx">
  211. <xsl:call-template name="write.chunk.with.doctype">
  212. <xsl:with-param name="filename" select="concat($chunk.base.dir, 'index.xml')"/>
  213. <xsl:with-param name="method" select="'xml'"/>
  214. <xsl:with-param name="indent" select="'yes'"/>
  215. <xsl:with-param name="doctype-public" select="''"/>
  216. <xsl:with-param name="doctype-system" select="''"/>
  217. <xsl:with-param name="encoding" select="'utf-8'"/>
  218. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  219. <xsl:with-param name="content">
  220. <xsl:call-template name="helpidx.content"/>
  221. </xsl:with-param>
  222. </xsl:call-template>
  223. </xsl:template>
  224. <xsl:template name="helpidx.content">
  225. <index>
  226. <xsl:choose>
  227. <xsl:when test="$rootid != ''">
  228. <xsl:apply-templates select="key('id',$rootid)//indexterm" mode="idx">
  229. <xsl:sort select="normalize-space(concat(primary/@sortas, primary[not(@sortas) or @sortas = '']))"/>
  230. <xsl:sort select="normalize-space(concat(secondary/@sortas, secondary[not(@sortas) or @sortas = '']))"/>
  231. <xsl:sort select="normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas) or @sortas = '']))"/>
  232. </xsl:apply-templates>
  233. </xsl:when>
  234. <xsl:otherwise>
  235. <xsl:apply-templates select="//indexterm" mode="idx">
  236. <xsl:sort select="normalize-space(concat(primary/@sortas, primary[not(@sortas) or @sortas = '']))"/>
  237. <xsl:sort select="normalize-space(concat(secondary/@sortas, secondary[not(@sortas) or @sortas = '']))"/>
  238. <xsl:sort select="normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas) or @sortas = '']))"/>
  239. </xsl:apply-templates>
  240. </xsl:otherwise>
  241. </xsl:choose>
  242. </index>
  243. </xsl:template>
  244. <xsl:template match="indexterm[@class='endofrange']" mode="idx"/>
  245. <xsl:template match="indexterm|primary|secondary|tertiary" mode="idx">
  246. <xsl:variable name="href">
  247. <xsl:call-template name="href.target.with.base.dir">
  248. <xsl:with-param name="context" select="/"/> <!-- Generate links relative to the location of root file/toc.xml file -->
  249. </xsl:call-template>
  250. </xsl:variable>
  251. <xsl:variable name="text">
  252. <xsl:value-of select="normalize-space(.)"/>
  253. <xsl:if test="following-sibling::*[1][self::see]">
  254. <xsl:text> (</xsl:text><xsl:call-template name="gentext">
  255. <xsl:with-param name="key" select="'see'"/>
  256. </xsl:call-template><xsl:text> </xsl:text>
  257. <xsl:value-of select="following-sibling::*[1][self::see]"/>)</xsl:if>
  258. </xsl:variable>
  259. <xsl:choose>
  260. <xsl:when test="self::indexterm">
  261. <xsl:apply-templates select="primary" mode="idx"/>
  262. </xsl:when>
  263. <xsl:when test="self::primary">
  264. <entry keyword="{$text}">
  265. <topic href="{$href}"/>
  266. <xsl:apply-templates select="following-sibling::secondary" mode="idx"/>
  267. </entry>
  268. </xsl:when>
  269. <xsl:otherwise>
  270. <entry keyword="{$text}">
  271. <topic href="{$href}"/>
  272. <xsl:apply-templates select="following-sibling::tertiary" mode="idx"/>
  273. </entry>
  274. </xsl:otherwise>
  275. </xsl:choose>
  276. </xsl:template>
  277. <!-- ==================================================================== -->
  278. </xsl:stylesheet>