chunktoc.xsl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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: chunktoc.xsl 9286 2012-04-19 10:10:58Z bobstayton $
  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="$chunk.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="topic">
  129. <xsl:call-template name="process-chunk"/>
  130. </xsl:template>
  131. <xsl:template match="article/appendix">
  132. <xsl:call-template name="process-chunk"/>
  133. </xsl:template>
  134. <xsl:template match="article/glossary">
  135. <xsl:call-template name="process-chunk"/>
  136. </xsl:template>
  137. <xsl:template match="article/bibliography">
  138. <xsl:call-template name="process-chunk"/>
  139. </xsl:template>
  140. <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
  141. <xsl:variable name="ischunk">
  142. <xsl:call-template name="chunk"/>
  143. </xsl:variable>
  144. <xsl:choose>
  145. <xsl:when test="$ischunk != 0">
  146. <xsl:call-template name="process-chunk"/>
  147. </xsl:when>
  148. <xsl:otherwise>
  149. <xsl:apply-imports/>
  150. </xsl:otherwise>
  151. </xsl:choose>
  152. </xsl:template>
  153. <xsl:template match="setindex |book/index |article/index">
  154. <!-- some implementations use completely empty index tags to indicate -->
  155. <!-- where an automatically generated index should be inserted. so -->
  156. <!-- if the index is completely empty, skip it. -->
  157. <xsl:if test="count(*)&gt;0 or $generate.index != '0'">
  158. <xsl:call-template name="process-chunk"/>
  159. </xsl:if>
  160. </xsl:template>
  161. <!-- ==================================================================== -->
  162. <xsl:template match="/">
  163. <!-- * Get a title for current doc so that we let the user -->
  164. <!-- * know what document we are processing at this point. -->
  165. <xsl:variable name="doc.title">
  166. <xsl:call-template name="get.doc.title"/>
  167. </xsl:variable>
  168. <xsl:choose>
  169. <xsl:when test="$chunk.toc = ''">
  170. <xsl:message terminate="yes">
  171. <xsl:text>The chunk.toc file is not set.</xsl:text>
  172. </xsl:message>
  173. </xsl:when>
  174. <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
  175. toss the namespace and continue. Use the docbook5 namespaced
  176. stylesheets for DocBook5 if you don't want to use this feature.-->
  177. <!-- include extra test for Xalan quirk -->
  178. <xsl:when test="$exsl.node.set.available != 0 and (*/self::ng:* or */self::db:*)">
  179. <xsl:call-template name="log.message">
  180. <xsl:with-param name="level">Note</xsl:with-param>
  181. <xsl:with-param name="source" select="$doc.title"/>
  182. <xsl:with-param name="context-desc">
  183. <xsl:text>namesp. cut</xsl:text>
  184. </xsl:with-param>
  185. <xsl:with-param name="message">
  186. <xsl:text>stripped namespace before processing</xsl:text>
  187. </xsl:with-param>
  188. </xsl:call-template>
  189. <xsl:variable name="nons">
  190. <xsl:apply-templates mode="stripNS"/>
  191. </xsl:variable>
  192. <xsl:call-template name="log.message">
  193. <xsl:with-param name="level">Note</xsl:with-param>
  194. <xsl:with-param name="source" select="$doc.title"/>
  195. <xsl:with-param name="context-desc">
  196. <xsl:text>namesp. cut</xsl:text>
  197. </xsl:with-param>
  198. <xsl:with-param name="message">
  199. <xsl:text>processing stripped document</xsl:text>
  200. </xsl:with-param>
  201. </xsl:call-template>
  202. <xsl:apply-templates select="exsl:node-set($nons)"/>
  203. </xsl:when>
  204. <!-- Can't process unless namespace removed -->
  205. <xsl:when test="*/self::ng:* or */self::db:*">
  206. <xsl:message terminate="yes">
  207. <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
  208. <xsl:text> cannot proceed.</xsl:text>
  209. </xsl:message>
  210. </xsl:when>
  211. <xsl:otherwise>
  212. <xsl:choose>
  213. <xsl:when test="$rootid != ''">
  214. <xsl:choose>
  215. <xsl:when test="count(key('id',$rootid)) = 0">
  216. <xsl:message terminate="yes">
  217. <xsl:text>ID '</xsl:text>
  218. <xsl:value-of select="$rootid"/>
  219. <xsl:text>' not found in document.</xsl:text>
  220. </xsl:message>
  221. </xsl:when>
  222. <xsl:otherwise>
  223. <xsl:if test="$collect.xref.targets = 'yes' or $collect.xref.targets = 'only'">
  224. <xsl:apply-templates select="key('id', $rootid)" mode="collect.targets"/>
  225. </xsl:if>
  226. <xsl:if test="$collect.xref.targets != 'only'">
  227. <xsl:apply-templates select="key('id',$rootid)" mode="process.root"/>
  228. <xsl:if test="$tex.math.in.alt != ''">
  229. <xsl:apply-templates select="key('id',$rootid)" mode="collect.tex.math"/>
  230. </xsl:if>
  231. <xsl:if test="$generate.manifest != 0">
  232. <xsl:call-template name="generate.manifest">
  233. <xsl:with-param name="node" select="key('id',$rootid)"/>
  234. </xsl:call-template>
  235. </xsl:if>
  236. </xsl:if>
  237. </xsl:otherwise>
  238. </xsl:choose>
  239. </xsl:when>
  240. <xsl:otherwise>
  241. <xsl:if test="$collect.xref.targets = 'yes' or $collect.xref.targets = 'only'">
  242. <xsl:apply-templates select="/" mode="collect.targets"/>
  243. </xsl:if>
  244. <xsl:if test="$collect.xref.targets != 'only'">
  245. <xsl:apply-templates select="/" mode="process.root"/>
  246. <xsl:if test="$tex.math.in.alt != ''">
  247. <xsl:apply-templates select="/" mode="collect.tex.math"/>
  248. </xsl:if>
  249. <xsl:if test="$generate.manifest != 0">
  250. <xsl:call-template name="generate.manifest">
  251. <xsl:with-param name="node" select="/"/>
  252. </xsl:call-template>
  253. </xsl:if>
  254. </xsl:if>
  255. </xsl:otherwise>
  256. </xsl:choose>
  257. </xsl:otherwise>
  258. </xsl:choose>
  259. </xsl:template>
  260. <xsl:template match="*" mode="process.root">
  261. <xsl:apply-templates select="."/>
  262. <xsl:call-template name="generate.css"/>
  263. </xsl:template>
  264. <xsl:template name="make.lots">
  265. <xsl:param name="toc.params" select="''"/>
  266. <xsl:param name="toc"/>
  267. <xsl:variable name="lots">
  268. <xsl:if test="contains($toc.params, 'toc')">
  269. <xsl:copy-of select="$toc"/>
  270. </xsl:if>
  271. <xsl:if test="contains($toc.params, 'figure')">
  272. <xsl:choose>
  273. <xsl:when test="$chunk.separate.lots != '0'">
  274. <xsl:call-template name="make.lot.chunk">
  275. <xsl:with-param name="type" select="'figure'"/>
  276. <xsl:with-param name="lot">
  277. <xsl:call-template name="list.of.titles">
  278. <xsl:with-param name="titles" select="'figure'"/>
  279. <xsl:with-param name="nodes" select=".//figure"/>
  280. </xsl:call-template>
  281. </xsl:with-param>
  282. </xsl:call-template>
  283. </xsl:when>
  284. <xsl:otherwise>
  285. <xsl:call-template name="list.of.titles">
  286. <xsl:with-param name="titles" select="'figure'"/>
  287. <xsl:with-param name="nodes" select=".//figure"/>
  288. </xsl:call-template>
  289. </xsl:otherwise>
  290. </xsl:choose>
  291. </xsl:if>
  292. <xsl:if test="contains($toc.params, 'table')">
  293. <xsl:choose>
  294. <xsl:when test="$chunk.separate.lots != '0'">
  295. <xsl:call-template name="make.lot.chunk">
  296. <xsl:with-param name="type" select="'table'"/>
  297. <xsl:with-param name="lot">
  298. <xsl:call-template name="list.of.titles">
  299. <xsl:with-param name="titles" select="'table'"/>
  300. <xsl:with-param name="nodes" select=".//table"/>
  301. </xsl:call-template>
  302. </xsl:with-param>
  303. </xsl:call-template>
  304. </xsl:when>
  305. <xsl:otherwise>
  306. <xsl:call-template name="list.of.titles">
  307. <xsl:with-param name="titles" select="'table'"/>
  308. <xsl:with-param name="nodes" select=".//table"/>
  309. </xsl:call-template>
  310. </xsl:otherwise>
  311. </xsl:choose>
  312. </xsl:if>
  313. <xsl:if test="contains($toc.params, 'example')">
  314. <xsl:choose>
  315. <xsl:when test="$chunk.separate.lots != '0'">
  316. <xsl:call-template name="make.lot.chunk">
  317. <xsl:with-param name="type" select="'example'"/>
  318. <xsl:with-param name="lot">
  319. <xsl:call-template name="list.of.titles">
  320. <xsl:with-param name="titles" select="'example'"/>
  321. <xsl:with-param name="nodes" select=".//example"/>
  322. </xsl:call-template>
  323. </xsl:with-param>
  324. </xsl:call-template>
  325. </xsl:when>
  326. <xsl:otherwise>
  327. <xsl:call-template name="list.of.titles">
  328. <xsl:with-param name="titles" select="'example'"/>
  329. <xsl:with-param name="nodes" select=".//example"/>
  330. </xsl:call-template>
  331. </xsl:otherwise>
  332. </xsl:choose>
  333. </xsl:if>
  334. <xsl:if test="contains($toc.params, 'equation')">
  335. <xsl:choose>
  336. <xsl:when test="$chunk.separate.lots != '0'">
  337. <xsl:call-template name="make.lot.chunk">
  338. <xsl:with-param name="type" select="'equation'"/>
  339. <xsl:with-param name="lot">
  340. <xsl:call-template name="list.of.titles">
  341. <xsl:with-param name="titles" select="'equation'"/>
  342. <xsl:with-param name="nodes" select=".//equation"/>
  343. </xsl:call-template>
  344. </xsl:with-param>
  345. </xsl:call-template>
  346. </xsl:when>
  347. <xsl:otherwise>
  348. <xsl:call-template name="list.of.titles">
  349. <xsl:with-param name="titles" select="'equation'"/>
  350. <xsl:with-param name="nodes" select=".//equation"/>
  351. </xsl:call-template>
  352. </xsl:otherwise>
  353. </xsl:choose>
  354. </xsl:if>
  355. <xsl:if test="contains($toc.params, 'procedure')">
  356. <xsl:choose>
  357. <xsl:when test="$chunk.separate.lots != '0'">
  358. <xsl:call-template name="make.lot.chunk">
  359. <xsl:with-param name="type" select="'procedure'"/>
  360. <xsl:with-param name="lot">
  361. <xsl:call-template name="list.of.titles">
  362. <xsl:with-param name="titles" select="'procedure'"/>
  363. <xsl:with-param name="nodes" select=".//procedure[title]"/>
  364. </xsl:call-template>
  365. </xsl:with-param>
  366. </xsl:call-template>
  367. </xsl:when>
  368. <xsl:otherwise>
  369. <xsl:call-template name="list.of.titles">
  370. <xsl:with-param name="titles" select="'procedure'"/>
  371. <xsl:with-param name="nodes" select=".//procedure[title]"/>
  372. </xsl:call-template>
  373. </xsl:otherwise>
  374. </xsl:choose>
  375. </xsl:if>
  376. </xsl:variable>
  377. <xsl:if test="string($lots) != ''">
  378. <xsl:choose>
  379. <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
  380. <xsl:call-template name="write.chunk">
  381. <xsl:with-param name="filename">
  382. <xsl:call-template name="make-relative-filename">
  383. <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
  384. <xsl:with-param name="base.name">
  385. <xsl:call-template name="dbhtml-dir"/>
  386. <xsl:apply-templates select="." mode="recursive-chunk-filename">
  387. <xsl:with-param name="recursive" select="true()"/>
  388. </xsl:apply-templates>
  389. <xsl:text>-toc</xsl:text>
  390. <xsl:value-of select="$html.ext"/>
  391. </xsl:with-param>
  392. </xsl:call-template>
  393. </xsl:with-param>
  394. <xsl:with-param name="content">
  395. <xsl:call-template name="chunk-element-content">
  396. <xsl:with-param name="prev" select="/foo"/>
  397. <xsl:with-param name="next" select="/foo"/>
  398. <xsl:with-param name="nav.context" select="'toc'"/>
  399. <xsl:with-param name="content">
  400. <h1>
  401. <xsl:apply-templates select="." mode="object.title.markup"/>
  402. </h1>
  403. <xsl:copy-of select="$lots"/>
  404. </xsl:with-param>
  405. </xsl:call-template>
  406. </xsl:with-param>
  407. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  408. </xsl:call-template>
  409. </xsl:when>
  410. <xsl:otherwise>
  411. <xsl:copy-of select="$lots"/>
  412. </xsl:otherwise>
  413. </xsl:choose>
  414. </xsl:if>
  415. </xsl:template>
  416. <xsl:template name="make.lot.chunk">
  417. <xsl:param name="type" select="''"/>
  418. <xsl:param name="lot"/>
  419. <xsl:if test="string($lot) != ''">
  420. <xsl:variable name="filename">
  421. <xsl:call-template name="make-relative-filename">
  422. <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
  423. <xsl:with-param name="base.name">
  424. <xsl:call-template name="dbhtml-dir"/>
  425. <xsl:value-of select="$type"/>
  426. <xsl:text>-toc</xsl:text>
  427. <xsl:value-of select="$html.ext"/>
  428. </xsl:with-param>
  429. </xsl:call-template>
  430. </xsl:variable>
  431. <xsl:variable name="href">
  432. <xsl:call-template name="make-relative-filename">
  433. <xsl:with-param name="base.dir" select="''"/>
  434. <xsl:with-param name="base.name">
  435. <xsl:call-template name="dbhtml-dir"/>
  436. <xsl:value-of select="$type"/>
  437. <xsl:text>-toc</xsl:text>
  438. <xsl:value-of select="$html.ext"/>
  439. </xsl:with-param>
  440. </xsl:call-template>
  441. </xsl:variable>
  442. <xsl:call-template name="write.chunk">
  443. <xsl:with-param name="filename" select="$filename"/>
  444. <xsl:with-param name="content">
  445. <xsl:call-template name="chunk-element-content">
  446. <xsl:with-param name="prev" select="/foo"/>
  447. <xsl:with-param name="next" select="/foo"/>
  448. <xsl:with-param name="nav.context" select="'toc'"/>
  449. <xsl:with-param name="content">
  450. <xsl:copy-of select="$lot"/>
  451. </xsl:with-param>
  452. </xsl:call-template>
  453. </xsl:with-param>
  454. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  455. </xsl:call-template>
  456. <!-- And output a link to this file -->
  457. <div>
  458. <xsl:attribute name="class">
  459. <xsl:text>ListofTitles</xsl:text>
  460. </xsl:attribute>
  461. <a href="{$href}">
  462. <xsl:call-template name="gentext">
  463. <xsl:with-param name="key">
  464. <xsl:choose>
  465. <xsl:when test="$type='table'">ListofTables</xsl:when>
  466. <xsl:when test="$type='figure'">ListofFigures</xsl:when>
  467. <xsl:when test="$type='equation'">ListofEquations</xsl:when>
  468. <xsl:when test="$type='example'">ListofExamples</xsl:when>
  469. <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
  470. <xsl:otherwise>ListofUnknown</xsl:otherwise>
  471. </xsl:choose>
  472. </xsl:with-param>
  473. </xsl:call-template>
  474. </a>
  475. </div>
  476. </xsl:if>
  477. </xsl:template>
  478. </xsl:stylesheet>