chunktoc.xsl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <?xml version="1.0" encoding="ASCII"?>
  2. <!--This file was created automatically by html2xhtml-->
  3. <!--from the HTML stylesheets.-->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" xmlns="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="doc">
  5. <!-- ********************************************************************
  6. $Id$
  7. ********************************************************************
  8. This file is part of the XSL DocBook Stylesheet distribution.
  9. See ../README or http://docbook.sf.net/release/xsl/current/ for
  10. copyright and other information.
  11. ******************************************************************** -->
  12. <!-- ==================================================================== -->
  13. <xsl:import href="docbook.xsl"/>
  14. <xsl:import href="chunk-common.xsl"/>
  15. <xsl:template name="chunk">
  16. <xsl:param name="node" select="."/>
  17. <!-- returns 1 if $node is a chunk -->
  18. <xsl:variable name="id">
  19. <xsl:call-template name="object.id">
  20. <xsl:with-param name="object" select="$node"/>
  21. </xsl:call-template>
  22. </xsl:variable>
  23. <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
  24. <xsl:choose>
  25. <xsl:when test="$chunks//tocentry[@linkend=$id]">1</xsl:when>
  26. <xsl:otherwise>0</xsl:otherwise>
  27. </xsl:choose>
  28. </xsl:template>
  29. <!-- ==================================================================== -->
  30. <xsl:template match="*" mode="chunk-filename">
  31. <!-- returns the filename of a chunk -->
  32. <xsl:variable name="id">
  33. <xsl:call-template name="object.id"/>
  34. </xsl:variable>
  35. <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
  36. <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
  37. <xsl:variable name="filename">
  38. <xsl:call-template name="pi.dbhtml_filename">
  39. <xsl:with-param name="node" select="$chunk"/>
  40. </xsl:call-template>
  41. </xsl:variable>
  42. <xsl:choose>
  43. <xsl:when test="$chunk">
  44. <xsl:value-of select="$filename"/>
  45. </xsl:when>
  46. <xsl:otherwise>
  47. <xsl:apply-templates select="parent::*" mode="chunk-filename"/>
  48. </xsl:otherwise>
  49. </xsl:choose>
  50. </xsl:template>
  51. <!-- ==================================================================== -->
  52. <xsl:template name="process-chunk">
  53. <xsl:variable name="id">
  54. <xsl:call-template name="object.id"/>
  55. </xsl:variable>
  56. <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
  57. <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
  58. <xsl:variable name="prev-id" select="($chunk/preceding::tocentry |$chunk/ancestor::tocentry)[last()]/@linkend"/>
  59. <xsl:variable name="next-id" select="($chunk/following::tocentry |$chunk/child::tocentry)[1]/@linkend"/>
  60. <xsl:variable name="prev" select="key('id',$prev-id)"/>
  61. <xsl:variable name="next" select="key('id',$next-id)"/>
  62. <xsl:variable name="ischunk">
  63. <xsl:call-template name="chunk"/>
  64. </xsl:variable>
  65. <xsl:variable name="chunkfn">
  66. <xsl:if test="$ischunk='1'">
  67. <xsl:apply-templates mode="chunk-filename" select="."/>
  68. </xsl:if>
  69. </xsl:variable>
  70. <xsl:variable name="filename">
  71. <xsl:call-template name="make-relative-filename">
  72. <xsl:with-param name="base.dir" select="$base.dir"/>
  73. <xsl:with-param name="base.name" select="$chunkfn"/>
  74. </xsl:call-template>
  75. </xsl:variable>
  76. <xsl:choose>
  77. <xsl:when test="$ischunk = 0">
  78. <xsl:apply-imports/>
  79. </xsl:when>
  80. <xsl:otherwise>
  81. <xsl:call-template name="write.chunk">
  82. <xsl:with-param name="filename" select="$filename"/>
  83. <xsl:with-param name="content">
  84. <xsl:call-template name="chunk-element-content">
  85. <xsl:with-param name="prev" select="$prev"/>
  86. <xsl:with-param name="next" select="$next"/>
  87. </xsl:call-template>
  88. </xsl:with-param>
  89. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  90. </xsl:call-template>
  91. </xsl:otherwise>
  92. </xsl:choose>
  93. </xsl:template>
  94. <!-- ==================================================================== -->
  95. <xsl:template match="set">
  96. <xsl:call-template name="process-chunk"/>
  97. </xsl:template>
  98. <xsl:template match="book">
  99. <xsl:call-template name="process-chunk"/>
  100. </xsl:template>
  101. <xsl:template match="book/appendix">
  102. <xsl:call-template name="process-chunk"/>
  103. </xsl:template>
  104. <xsl:template match="book/glossary">
  105. <xsl:call-template name="process-chunk"/>
  106. </xsl:template>
  107. <xsl:template match="book/bibliography">
  108. <xsl:call-template name="process-chunk"/>
  109. </xsl:template>
  110. <xsl:template match="dedication" mode="dedication">
  111. <xsl:call-template name="process-chunk"/>
  112. </xsl:template>
  113. <xsl:template match="preface|chapter">
  114. <xsl:call-template name="process-chunk"/>
  115. </xsl:template>
  116. <xsl:template match="part|reference">
  117. <xsl:call-template name="process-chunk"/>
  118. </xsl:template>
  119. <xsl:template match="refentry">
  120. <xsl:call-template name="process-chunk"/>
  121. </xsl:template>
  122. <xsl:template match="colophon">
  123. <xsl:call-template name="process-chunk"/>
  124. </xsl:template>
  125. <xsl:template match="article">
  126. <xsl:call-template name="process-chunk"/>
  127. </xsl:template>
  128. <xsl:template match="article/appendix">
  129. <xsl:call-template name="process-chunk"/>
  130. </xsl:template>
  131. <xsl:template match="article/glossary">
  132. <xsl:call-template name="process-chunk"/>
  133. </xsl:template>
  134. <xsl:template match="article/bibliography">
  135. <xsl:call-template name="process-chunk"/>
  136. </xsl:template>
  137. <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
  138. <xsl:variable name="ischunk">
  139. <xsl:call-template name="chunk"/>
  140. </xsl:variable>
  141. <xsl:choose>
  142. <xsl:when test="$ischunk != 0">
  143. <xsl:call-template name="process-chunk"/>
  144. </xsl:when>
  145. <xsl:otherwise>
  146. <xsl:apply-imports/>
  147. </xsl:otherwise>
  148. </xsl:choose>
  149. </xsl:template>
  150. <xsl:template match="setindex |book/index |article/index">
  151. <!-- some implementations use completely empty index tags to indicate -->
  152. <!-- where an automatically generated index should be inserted. so -->
  153. <!-- if the index is completely empty, skip it. -->
  154. <xsl:if test="count(*)&gt;0 or $generate.index != '0'">
  155. <xsl:call-template name="process-chunk"/>
  156. </xsl:if>
  157. </xsl:template>
  158. <!-- ==================================================================== -->
  159. <xsl:template match="/">
  160. <xsl:choose>
  161. <xsl:when test="$chunk.toc = ''">
  162. <xsl:message terminate="yes">
  163. <xsl:text>The chunk.toc file is not set.</xsl:text>
  164. </xsl:message>
  165. </xsl:when>
  166. <xsl:when test="$rootid != ''">
  167. <xsl:choose>
  168. <xsl:when test="count(key('id',$rootid)) = 0">
  169. <xsl:message terminate="yes">
  170. <xsl:text>ID '</xsl:text>
  171. <xsl:value-of select="$rootid"/>
  172. <xsl:text>' not found in document.</xsl:text>
  173. </xsl:message>
  174. </xsl:when>
  175. <xsl:otherwise>
  176. <xsl:apply-templates select="key('id',$rootid)"/>
  177. </xsl:otherwise>
  178. </xsl:choose>
  179. </xsl:when>
  180. <xsl:otherwise>
  181. <xsl:apply-templates select="/" mode="process.root"/>
  182. </xsl:otherwise>
  183. </xsl:choose>
  184. </xsl:template>
  185. <xsl:template match="*" mode="process.root">
  186. <xsl:apply-templates select="."/>
  187. </xsl:template>
  188. <xsl:template name="make.lots">
  189. <xsl:param name="toc.params" select="''"/>
  190. <xsl:param name="toc"/>
  191. <xsl:variable name="lots">
  192. <xsl:if test="contains($toc.params, 'toc')">
  193. <xsl:copy-of select="$toc"/>
  194. </xsl:if>
  195. <xsl:if test="contains($toc.params, 'figure')">
  196. <xsl:choose>
  197. <xsl:when test="$chunk.separate.lots != '0'">
  198. <xsl:call-template name="make.lot.chunk">
  199. <xsl:with-param name="type" select="'figure'"/>
  200. <xsl:with-param name="lot">
  201. <xsl:call-template name="list.of.titles">
  202. <xsl:with-param name="titles" select="'figure'"/>
  203. <xsl:with-param name="nodes" select=".//figure"/>
  204. </xsl:call-template>
  205. </xsl:with-param>
  206. </xsl:call-template>
  207. </xsl:when>
  208. <xsl:otherwise>
  209. <xsl:call-template name="list.of.titles">
  210. <xsl:with-param name="titles" select="'figure'"/>
  211. <xsl:with-param name="nodes" select=".//figure"/>
  212. </xsl:call-template>
  213. </xsl:otherwise>
  214. </xsl:choose>
  215. </xsl:if>
  216. <xsl:if test="contains($toc.params, 'table')">
  217. <xsl:choose>
  218. <xsl:when test="$chunk.separate.lots != '0'">
  219. <xsl:call-template name="make.lot.chunk">
  220. <xsl:with-param name="type" select="'table'"/>
  221. <xsl:with-param name="lot">
  222. <xsl:call-template name="list.of.titles">
  223. <xsl:with-param name="titles" select="'table'"/>
  224. <xsl:with-param name="nodes" select=".//table"/>
  225. </xsl:call-template>
  226. </xsl:with-param>
  227. </xsl:call-template>
  228. </xsl:when>
  229. <xsl:otherwise>
  230. <xsl:call-template name="list.of.titles">
  231. <xsl:with-param name="titles" select="'table'"/>
  232. <xsl:with-param name="nodes" select=".//table"/>
  233. </xsl:call-template>
  234. </xsl:otherwise>
  235. </xsl:choose>
  236. </xsl:if>
  237. <xsl:if test="contains($toc.params, 'example')">
  238. <xsl:choose>
  239. <xsl:when test="$chunk.separate.lots != '0'">
  240. <xsl:call-template name="make.lot.chunk">
  241. <xsl:with-param name="type" select="'example'"/>
  242. <xsl:with-param name="lot">
  243. <xsl:call-template name="list.of.titles">
  244. <xsl:with-param name="titles" select="'example'"/>
  245. <xsl:with-param name="nodes" select=".//example"/>
  246. </xsl:call-template>
  247. </xsl:with-param>
  248. </xsl:call-template>
  249. </xsl:when>
  250. <xsl:otherwise>
  251. <xsl:call-template name="list.of.titles">
  252. <xsl:with-param name="titles" select="'example'"/>
  253. <xsl:with-param name="nodes" select=".//example"/>
  254. </xsl:call-template>
  255. </xsl:otherwise>
  256. </xsl:choose>
  257. </xsl:if>
  258. <xsl:if test="contains($toc.params, 'equation')">
  259. <xsl:choose>
  260. <xsl:when test="$chunk.separate.lots != '0'">
  261. <xsl:call-template name="make.lot.chunk">
  262. <xsl:with-param name="type" select="'equation'"/>
  263. <xsl:with-param name="lot">
  264. <xsl:call-template name="list.of.titles">
  265. <xsl:with-param name="titles" select="'equation'"/>
  266. <xsl:with-param name="nodes" select=".//equation"/>
  267. </xsl:call-template>
  268. </xsl:with-param>
  269. </xsl:call-template>
  270. </xsl:when>
  271. <xsl:otherwise>
  272. <xsl:call-template name="list.of.titles">
  273. <xsl:with-param name="titles" select="'equation'"/>
  274. <xsl:with-param name="nodes" select=".//equation"/>
  275. </xsl:call-template>
  276. </xsl:otherwise>
  277. </xsl:choose>
  278. </xsl:if>
  279. <xsl:if test="contains($toc.params, 'procedure')">
  280. <xsl:choose>
  281. <xsl:when test="$chunk.separate.lots != '0'">
  282. <xsl:call-template name="make.lot.chunk">
  283. <xsl:with-param name="type" select="'procedure'"/>
  284. <xsl:with-param name="lot">
  285. <xsl:call-template name="list.of.titles">
  286. <xsl:with-param name="titles" select="'procedure'"/>
  287. <xsl:with-param name="nodes" select=".//procedure[title]"/>
  288. </xsl:call-template>
  289. </xsl:with-param>
  290. </xsl:call-template>
  291. </xsl:when>
  292. <xsl:otherwise>
  293. <xsl:call-template name="list.of.titles">
  294. <xsl:with-param name="titles" select="'procedure'"/>
  295. <xsl:with-param name="nodes" select=".//procedure[title]"/>
  296. </xsl:call-template>
  297. </xsl:otherwise>
  298. </xsl:choose>
  299. </xsl:if>
  300. </xsl:variable>
  301. <xsl:if test="string($lots) != ''">
  302. <xsl:choose>
  303. <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
  304. <xsl:call-template name="write.chunk">
  305. <xsl:with-param name="filename">
  306. <xsl:call-template name="make-relative-filename">
  307. <xsl:with-param name="base.dir" select="$base.dir"/>
  308. <xsl:with-param name="base.name">
  309. <xsl:call-template name="dbhtml-dir"/>
  310. <xsl:apply-templates select="." mode="recursive-chunk-filename">
  311. <xsl:with-param name="recursive" select="true()"/>
  312. </xsl:apply-templates>
  313. <xsl:text>-toc</xsl:text>
  314. <xsl:value-of select="$html.ext"/>
  315. </xsl:with-param>
  316. </xsl:call-template>
  317. </xsl:with-param>
  318. <xsl:with-param name="content">
  319. <xsl:call-template name="chunk-element-content">
  320. <xsl:with-param name="prev" select="/foo"/>
  321. <xsl:with-param name="next" select="/foo"/>
  322. <xsl:with-param name="nav.context" select="'toc'"/>
  323. <xsl:with-param name="content">
  324. <h1>
  325. <xsl:apply-templates select="." mode="object.title.markup"/>
  326. </h1>
  327. <xsl:copy-of select="$lots"/>
  328. </xsl:with-param>
  329. </xsl:call-template>
  330. </xsl:with-param>
  331. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  332. </xsl:call-template>
  333. </xsl:when>
  334. <xsl:otherwise>
  335. <xsl:copy-of select="$lots"/>
  336. </xsl:otherwise>
  337. </xsl:choose>
  338. </xsl:if>
  339. </xsl:template>
  340. <xsl:template name="make.lot.chunk">
  341. <xsl:param name="type" select="''"/>
  342. <xsl:param name="lot"/>
  343. <xsl:if test="string($lot) != ''">
  344. <xsl:variable name="filename">
  345. <xsl:call-template name="make-relative-filename">
  346. <xsl:with-param name="base.dir" select="$base.dir"/>
  347. <xsl:with-param name="base.name">
  348. <xsl:call-template name="dbhtml-dir"/>
  349. <xsl:value-of select="$type"/>
  350. <xsl:text>-toc</xsl:text>
  351. <xsl:value-of select="$html.ext"/>
  352. </xsl:with-param>
  353. </xsl:call-template>
  354. </xsl:variable>
  355. <xsl:variable name="href">
  356. <xsl:call-template name="make-relative-filename">
  357. <xsl:with-param name="base.name">
  358. <xsl:call-template name="dbhtml-dir"/>
  359. <xsl:value-of select="$type"/>
  360. <xsl:text>-toc</xsl:text>
  361. <xsl:value-of select="$html.ext"/>
  362. </xsl:with-param>
  363. </xsl:call-template>
  364. </xsl:variable>
  365. <xsl:call-template name="write.chunk">
  366. <xsl:with-param name="filename" select="$filename"/>
  367. <xsl:with-param name="content">
  368. <xsl:call-template name="chunk-element-content">
  369. <xsl:with-param name="prev" select="/foo"/>
  370. <xsl:with-param name="next" select="/foo"/>
  371. <xsl:with-param name="nav.context" select="'toc'"/>
  372. <xsl:with-param name="content">
  373. <xsl:copy-of select="$lot"/>
  374. </xsl:with-param>
  375. </xsl:call-template>
  376. </xsl:with-param>
  377. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  378. </xsl:call-template>
  379. <!-- And output a link to this file -->
  380. <div>
  381. <xsl:attribute name="class">
  382. <xsl:text>ListofTitles</xsl:text>
  383. </xsl:attribute>
  384. <a href="{$href}">
  385. <xsl:call-template name="gentext">
  386. <xsl:with-param name="key">
  387. <xsl:choose>
  388. <xsl:when test="$type='table'">ListofTables</xsl:when>
  389. <xsl:when test="$type='figure'">ListofFigures</xsl:when>
  390. <xsl:when test="$type='equation'">ListofEquations</xsl:when>
  391. <xsl:when test="$type='example'">ListofExamples</xsl:when>
  392. <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
  393. <xsl:otherwise>ListofUnknown</xsl:otherwise>
  394. </xsl:choose>
  395. </xsl:with-param>
  396. </xsl:call-template>
  397. </a>
  398. </div>
  399. </xsl:if>
  400. </xsl:template>
  401. </xsl:stylesheet>