autotoc.xsl 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. version='1.0'>
  4. <!-- ********************************************************************
  5. $Id: autotoc.xsl 9692 2012-12-16 02:31:34Z dcramer $
  6. ********************************************************************
  7. This file is part of the XSL DocBook Stylesheet distribution.
  8. See ../README or http://docbook.sf.net/release/xsl/current/ for
  9. copyright and other information.
  10. ******************************************************************** -->
  11. <xsl:variable name="toc.listitem.type">
  12. <xsl:choose>
  13. <xsl:when test="$toc.list.type = 'dl'">dt</xsl:when>
  14. <xsl:otherwise>li</xsl:otherwise>
  15. </xsl:choose>
  16. </xsl:variable>
  17. <!-- this is just hack because dl and ul aren't completely isomorphic -->
  18. <xsl:variable name="toc.dd.type">
  19. <xsl:choose>
  20. <xsl:when test="$toc.list.type = 'dl'">dd</xsl:when>
  21. <xsl:otherwise></xsl:otherwise>
  22. </xsl:choose>
  23. </xsl:variable>
  24. <xsl:template name="make.toc">
  25. <xsl:param name="toc-context" select="."/>
  26. <xsl:param name="toc.title.p" select="true()"/>
  27. <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  28. <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
  29. <xsl:variable name="toc.title">
  30. <xsl:if test="$toc.title.p">
  31. <xsl:choose>
  32. <xsl:when test="$make.clean.html != 0">
  33. <div class="toc-title">
  34. <xsl:call-template name="gentext">
  35. <xsl:with-param name="key">TableofContents</xsl:with-param>
  36. </xsl:call-template>
  37. </div>
  38. </xsl:when>
  39. <xsl:otherwise>
  40. <p>
  41. <b>
  42. <xsl:call-template name="gentext">
  43. <xsl:with-param name="key">TableofContents</xsl:with-param>
  44. </xsl:call-template>
  45. </b>
  46. </p>
  47. </xsl:otherwise>
  48. </xsl:choose>
  49. </xsl:if>
  50. </xsl:variable>
  51. <xsl:choose>
  52. <xsl:when test="$manual.toc != ''">
  53. <xsl:variable name="id">
  54. <xsl:call-template name="object.id"/>
  55. </xsl:variable>
  56. <xsl:variable name="toc" select="document($manual.toc, .)"/>
  57. <xsl:variable name="tocentry" select="$toc//tocentry[@linkend=$id]"/>
  58. <xsl:if test="$tocentry and $tocentry/*">
  59. <div class="toc">
  60. <xsl:copy-of select="$toc.title"/>
  61. <xsl:element name="{$toc.list.type}">
  62. <xsl:call-template name="toc.list.attributes">
  63. <xsl:with-param name="toc-context" select="$toc-context"/>
  64. <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
  65. <xsl:with-param name="nodes" select="$nodes"/>
  66. </xsl:call-template>
  67. <xsl:call-template name="manual-toc">
  68. <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
  69. </xsl:call-template>
  70. </xsl:element>
  71. </div>
  72. </xsl:if>
  73. </xsl:when>
  74. <xsl:otherwise>
  75. <xsl:choose>
  76. <xsl:when test="$qanda.in.toc != 0">
  77. <xsl:if test="$nodes.plus">
  78. <div class="toc">
  79. <xsl:copy-of select="$toc.title"/>
  80. <xsl:element name="{$toc.list.type}">
  81. <xsl:call-template name="toc.list.attributes">
  82. <xsl:with-param name="toc-context" select="$toc-context"/>
  83. <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
  84. <xsl:with-param name="nodes" select="$nodes"/>
  85. </xsl:call-template>
  86. <xsl:apply-templates select="$nodes.plus" mode="toc">
  87. <xsl:with-param name="toc-context" select="$toc-context"/>
  88. </xsl:apply-templates>
  89. </xsl:element>
  90. </div>
  91. </xsl:if>
  92. </xsl:when>
  93. <xsl:otherwise>
  94. <xsl:if test="$nodes">
  95. <div class="toc">
  96. <xsl:copy-of select="$toc.title"/>
  97. <xsl:element name="{$toc.list.type}">
  98. <xsl:call-template name="toc.list.attributes">
  99. <xsl:with-param name="toc-context" select="$toc-context"/>
  100. <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
  101. <xsl:with-param name="nodes" select="$nodes"/>
  102. </xsl:call-template>
  103. <xsl:apply-templates select="$nodes" mode="toc">
  104. <xsl:with-param name="toc-context" select="$toc-context"/>
  105. </xsl:apply-templates>
  106. </xsl:element>
  107. </div>
  108. </xsl:if>
  109. </xsl:otherwise>
  110. </xsl:choose>
  111. </xsl:otherwise>
  112. </xsl:choose>
  113. </xsl:template>
  114. <xsl:template name="toc.list.attributes">
  115. <xsl:param name="toc-context" select="."/>
  116. <xsl:param name="toc.title.p" select="true()"/>
  117. <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  118. <xsl:attribute name="class">toc</xsl:attribute>
  119. </xsl:template>
  120. <xsl:template name="make.lots">
  121. <xsl:param name="toc.params" select="''"/>
  122. <xsl:param name="toc"/>
  123. <xsl:if test="contains($toc.params, 'toc')">
  124. <xsl:copy-of select="$toc"/>
  125. </xsl:if>
  126. <xsl:if test="contains($toc.params, 'figure')">
  127. <xsl:call-template name="list.of.titles">
  128. <xsl:with-param name="titles" select="'figure'"/>
  129. <xsl:with-param name="nodes" select=".//figure"/>
  130. </xsl:call-template>
  131. </xsl:if>
  132. <xsl:if test="contains($toc.params, 'table')">
  133. <xsl:call-template name="list.of.titles">
  134. <xsl:with-param name="titles" select="'table'"/>
  135. <xsl:with-param name="nodes" select=".//table[not(@tocentry = 0)]"/>
  136. </xsl:call-template>
  137. </xsl:if>
  138. <xsl:if test="contains($toc.params, 'example')">
  139. <xsl:call-template name="list.of.titles">
  140. <xsl:with-param name="titles" select="'example'"/>
  141. <xsl:with-param name="nodes" select=".//example"/>
  142. </xsl:call-template>
  143. </xsl:if>
  144. <xsl:if test="contains($toc.params, 'equation')">
  145. <xsl:call-template name="list.of.titles">
  146. <xsl:with-param name="titles" select="'equation'"/>
  147. <xsl:with-param name="nodes" select=".//equation[title or info/title]"/>
  148. </xsl:call-template>
  149. </xsl:if>
  150. <xsl:if test="contains($toc.params, 'procedure')">
  151. <xsl:call-template name="list.of.titles">
  152. <xsl:with-param name="titles" select="'procedure'"/>
  153. <xsl:with-param name="nodes" select=".//procedure[title]"/>
  154. </xsl:call-template>
  155. </xsl:if>
  156. </xsl:template>
  157. <!-- ====================================================================== -->
  158. <xsl:template name="set.toc">
  159. <xsl:param name="toc-context" select="."/>
  160. <xsl:param name="toc.title.p" select="true()"/>
  161. <xsl:call-template name="make.toc">
  162. <xsl:with-param name="toc-context" select="$toc-context"/>
  163. <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
  164. <xsl:with-param name="nodes" select="book|setindex|set"/>
  165. </xsl:call-template>
  166. </xsl:template>
  167. <xsl:template name="division.toc">
  168. <xsl:param name="toc-context" select="."/>
  169. <xsl:param name="toc.title.p" select="true()"/>
  170. <xsl:call-template name="make.toc">
  171. <xsl:with-param name="toc-context" select="$toc-context"/>
  172. <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
  173. <xsl:with-param name="nodes" select="part|reference
  174. |preface|chapter|appendix
  175. |article
  176. |topic
  177. |bibliography|glossary|index
  178. |refentry
  179. |bridgehead[$bridgehead.in.toc != 0]"/>
  180. </xsl:call-template>
  181. </xsl:template>
  182. <xsl:template name="component.toc">
  183. <xsl:param name="toc-context" select="."/>
  184. <xsl:param name="toc.title.p" select="true()"/>
  185. <xsl:call-template name="make.toc">
  186. <xsl:with-param name="toc-context" select="$toc-context"/>
  187. <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
  188. <xsl:with-param name="nodes" select="section|sect1
  189. |simplesect[$simplesect.in.toc != 0]
  190. |topic
  191. |refentry
  192. |article|bibliography|glossary
  193. |appendix|index
  194. |bridgehead[not(@renderas)
  195. and $bridgehead.in.toc != 0]
  196. |.//bridgehead[@renderas='sect1'
  197. and $bridgehead.in.toc != 0]"/>
  198. </xsl:call-template>
  199. </xsl:template>
  200. <xsl:template name="component.toc.separator">
  201. <!-- Customize to output something between
  202. component.toc and first output -->
  203. </xsl:template>
  204. <xsl:template name="section.toc">
  205. <xsl:param name="toc-context" select="."/>
  206. <xsl:param name="toc.title.p" select="true()"/>
  207. <xsl:call-template name="make.toc">
  208. <xsl:with-param name="toc-context" select="$toc-context"/>
  209. <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
  210. <xsl:with-param name="nodes"
  211. select="section|sect1|sect2|sect3|sect4|sect5|refentry
  212. |bridgehead[$bridgehead.in.toc != 0]"/>
  213. </xsl:call-template>
  214. </xsl:template>
  215. <xsl:template name="section.toc.separator">
  216. <!-- Customize to output something between
  217. section.toc and first output -->
  218. </xsl:template>
  219. <!-- ==================================================================== -->
  220. <xsl:template name="subtoc">
  221. <xsl:param name="toc-context" select="."/>
  222. <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
  223. <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
  224. <xsl:variable name="subtoc">
  225. <xsl:element name="{$toc.list.type}">
  226. <xsl:choose>
  227. <xsl:when test="$qanda.in.toc != 0">
  228. <xsl:apply-templates mode="toc" select="$nodes.plus">
  229. <xsl:with-param name="toc-context" select="$toc-context"/>
  230. </xsl:apply-templates>
  231. </xsl:when>
  232. <xsl:otherwise>
  233. <xsl:apply-templates mode="toc" select="$nodes">
  234. <xsl:with-param name="toc-context" select="$toc-context"/>
  235. </xsl:apply-templates>
  236. </xsl:otherwise>
  237. </xsl:choose>
  238. </xsl:element>
  239. </xsl:variable>
  240. <xsl:variable name="depth">
  241. <xsl:choose>
  242. <xsl:when test="local-name(.) = 'section'">
  243. <xsl:value-of select="count(ancestor::section) + 1"/>
  244. </xsl:when>
  245. <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
  246. <xsl:when test="local-name(.) = 'sect2'">2</xsl:when>
  247. <xsl:when test="local-name(.) = 'sect3'">3</xsl:when>
  248. <xsl:when test="local-name(.) = 'sect4'">4</xsl:when>
  249. <xsl:when test="local-name(.) = 'sect5'">5</xsl:when>
  250. <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
  251. <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
  252. <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
  253. <xsl:when test="local-name(.) = 'topic'">1</xsl:when>
  254. <xsl:when test="local-name(.) = 'simplesect'">
  255. <!-- sigh... -->
  256. <xsl:choose>
  257. <xsl:when test="local-name(..) = 'section'">
  258. <xsl:value-of select="count(ancestor::section)"/>
  259. </xsl:when>
  260. <xsl:when test="local-name(..) = 'sect1'">2</xsl:when>
  261. <xsl:when test="local-name(..) = 'sect2'">3</xsl:when>
  262. <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
  263. <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
  264. <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
  265. <xsl:when test="local-name(..) = 'topic'">2</xsl:when>
  266. <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
  267. <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
  268. <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
  269. <xsl:otherwise>1</xsl:otherwise>
  270. </xsl:choose>
  271. </xsl:when>
  272. <xsl:otherwise>0</xsl:otherwise>
  273. </xsl:choose>
  274. </xsl:variable>
  275. <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
  276. <xsl:variable name="subtoc.list">
  277. <xsl:choose>
  278. <xsl:when test="$toc.dd.type = ''">
  279. <xsl:copy-of select="$subtoc"/>
  280. </xsl:when>
  281. <xsl:otherwise>
  282. <xsl:element name="{$toc.dd.type}">
  283. <xsl:copy-of select="$subtoc"/>
  284. </xsl:element>
  285. </xsl:otherwise>
  286. </xsl:choose>
  287. </xsl:variable>
  288. <xsl:element name="{$toc.listitem.type}">
  289. <xsl:call-template name="toc.line">
  290. <xsl:with-param name="toc-context" select="$toc-context"/>
  291. </xsl:call-template>
  292. <xsl:if test="$toc.listitem.type = 'li' and
  293. ( (self::set or self::book or self::part) or
  294. $toc.section.depth > $depth) and
  295. ( ($qanda.in.toc = 0 and count($nodes)&gt;0) or
  296. ($qanda.in.toc != 0 and count($nodes.plus)&gt;0) )
  297. and $toc.max.depth > $depth.from.context">
  298. <xsl:copy-of select="$subtoc.list"/>
  299. </xsl:if>
  300. </xsl:element>
  301. <xsl:if test="$toc.listitem.type != 'li' and
  302. ( (self::set or self::book or self::part) or
  303. $toc.section.depth > $depth) and
  304. ( ($qanda.in.toc = 0 and count($nodes)&gt;0) or
  305. ($qanda.in.toc != 0 and count($nodes.plus)&gt;0) )
  306. and $toc.max.depth > $depth.from.context">
  307. <xsl:copy-of select="$subtoc.list"/>
  308. </xsl:if>
  309. </xsl:template>
  310. <xsl:template name="toc.line">
  311. <xsl:param name="toc-context" select="."/>
  312. <xsl:param name="depth" select="1"/>
  313. <xsl:param name="depth.from.context" select="8"/>
  314. <span>
  315. <xsl:attribute name="class"><xsl:value-of select="local-name(.)"/></xsl:attribute>
  316. <!-- * if $autotoc.label.in.hyperlink is zero, then output the label -->
  317. <!-- * before the hyperlinked title (as the DSSSL stylesheet does) -->
  318. <xsl:if test="$autotoc.label.in.hyperlink = 0">
  319. <xsl:variable name="label">
  320. <xsl:apply-templates select="." mode="label.markup"/>
  321. </xsl:variable>
  322. <xsl:copy-of select="$label"/>
  323. <xsl:if test="$label != ''">
  324. <xsl:value-of select="$autotoc.label.separator"/>
  325. </xsl:if>
  326. </xsl:if>
  327. <a>
  328. <xsl:attribute name="href">
  329. <xsl:call-template name="href.target">
  330. <xsl:with-param name="context" select="$toc-context"/>
  331. <xsl:with-param name="toc-context" select="$toc-context"/>
  332. </xsl:call-template>
  333. </xsl:attribute>
  334. <!-- * if $autotoc.label.in.hyperlink is non-zero, then output the label -->
  335. <!-- * as part of the hyperlinked title -->
  336. <xsl:if test="not($autotoc.label.in.hyperlink = 0)">
  337. <xsl:variable name="label">
  338. <xsl:apply-templates select="." mode="label.markup"/>
  339. </xsl:variable>
  340. <xsl:copy-of select="$label"/>
  341. <xsl:if test="$label != ''">
  342. <xsl:value-of select="$autotoc.label.separator"/>
  343. </xsl:if>
  344. </xsl:if>
  345. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  346. </a>
  347. </span>
  348. </xsl:template>
  349. <xsl:template match="book" mode="toc">
  350. <xsl:param name="toc-context" select="."/>
  351. <xsl:call-template name="subtoc">
  352. <xsl:with-param name="toc-context" select="$toc-context"/>
  353. <xsl:with-param name="nodes" select="part|reference
  354. |preface|chapter|appendix
  355. |article
  356. |topic
  357. |bibliography|glossary|index
  358. |refentry
  359. |bridgehead[$bridgehead.in.toc != 0]"/>
  360. </xsl:call-template>
  361. </xsl:template>
  362. <xsl:template match="setindex" mode="toc">
  363. <xsl:param name="toc-context" select="."/>
  364. <!-- If the setindex tag is not empty, it should be it in the TOC -->
  365. <xsl:if test="* or $generate.index != 0">
  366. <xsl:call-template name="subtoc">
  367. <xsl:with-param name="toc-context" select="$toc-context"/>
  368. </xsl:call-template>
  369. </xsl:if>
  370. </xsl:template>
  371. <xsl:template match="part|reference" mode="toc">
  372. <xsl:param name="toc-context" select="."/>
  373. <xsl:call-template name="subtoc">
  374. <xsl:with-param name="toc-context" select="$toc-context"/>
  375. <xsl:with-param name="nodes" select="appendix|chapter|article|topic
  376. |index|glossary|bibliography
  377. |preface|reference|refentry
  378. |bridgehead[$bridgehead.in.toc != 0]"/>
  379. </xsl:call-template>
  380. </xsl:template>
  381. <xsl:template match="preface|chapter|appendix|article|topic" mode="toc">
  382. <xsl:param name="toc-context" select="."/>
  383. <xsl:call-template name="subtoc">
  384. <xsl:with-param name="toc-context" select="$toc-context"/>
  385. <xsl:with-param name="nodes" select="section|sect1
  386. |simplesect[$simplesect.in.toc != 0]
  387. |topic
  388. |refentry
  389. |glossary|bibliography|index
  390. |bridgehead[$bridgehead.in.toc != 0]"/>
  391. </xsl:call-template>
  392. </xsl:template>
  393. <xsl:template match="sect1" mode="toc">
  394. <xsl:param name="toc-context" select="."/>
  395. <xsl:call-template name="subtoc">
  396. <xsl:with-param name="toc-context" select="$toc-context"/>
  397. <xsl:with-param name="nodes" select="sect2
  398. |bridgehead[$bridgehead.in.toc != 0]"/>
  399. </xsl:call-template>
  400. </xsl:template>
  401. <xsl:template match="sect2" mode="toc">
  402. <xsl:param name="toc-context" select="."/>
  403. <xsl:call-template name="subtoc">
  404. <xsl:with-param name="toc-context" select="$toc-context"/>
  405. <xsl:with-param name="nodes" select="sect3
  406. |bridgehead[$bridgehead.in.toc != 0]"/>
  407. </xsl:call-template>
  408. </xsl:template>
  409. <xsl:template match="sect3" mode="toc">
  410. <xsl:param name="toc-context" select="."/>
  411. <xsl:call-template name="subtoc">
  412. <xsl:with-param name="toc-context" select="$toc-context"/>
  413. <xsl:with-param name="nodes" select="sect4
  414. |bridgehead[$bridgehead.in.toc != 0]"/>
  415. </xsl:call-template>
  416. </xsl:template>
  417. <xsl:template match="sect4" mode="toc">
  418. <xsl:param name="toc-context" select="."/>
  419. <xsl:call-template name="subtoc">
  420. <xsl:with-param name="toc-context" select="$toc-context"/>
  421. <xsl:with-param name="nodes" select="sect5
  422. |bridgehead[$bridgehead.in.toc != 0]"/>
  423. </xsl:call-template>
  424. </xsl:template>
  425. <xsl:template match="sect5" mode="toc">
  426. <xsl:param name="toc-context" select="."/>
  427. <xsl:call-template name="subtoc">
  428. <xsl:with-param name="toc-context" select="$toc-context"/>
  429. </xsl:call-template>
  430. </xsl:template>
  431. <xsl:template match="simplesect" mode="toc">
  432. <xsl:param name="toc-context" select="."/>
  433. <xsl:call-template name="subtoc">
  434. <xsl:with-param name="toc-context" select="$toc-context"/>
  435. </xsl:call-template>
  436. </xsl:template>
  437. <xsl:template match="section" mode="toc">
  438. <xsl:param name="toc-context" select="."/>
  439. <xsl:call-template name="subtoc">
  440. <xsl:with-param name="toc-context" select="$toc-context"/>
  441. <xsl:with-param name="nodes" select="section|refentry
  442. |simplesect[$simplesect.in.toc != 0]
  443. |bridgehead[$bridgehead.in.toc != 0]"/>
  444. </xsl:call-template>
  445. </xsl:template>
  446. <xsl:template match="topic" mode="toc">
  447. <xsl:param name="toc-context" select="."/>
  448. <xsl:call-template name="subtoc">
  449. <xsl:with-param name="toc-context" select="$toc-context"/>
  450. <xsl:with-param name="nodes" select="section|refentry
  451. |simplesect[$simplesect.in.toc != 0]
  452. |bridgehead[$bridgehead.in.toc != 0]"/>
  453. </xsl:call-template>
  454. </xsl:template>
  455. <xsl:template match="bridgehead" mode="toc">
  456. <xsl:param name="toc-context" select="."/>
  457. <xsl:if test="$bridgehead.in.toc != 0">
  458. <xsl:call-template name="subtoc">
  459. <xsl:with-param name="toc-context" select="$toc-context"/>
  460. </xsl:call-template>
  461. </xsl:if>
  462. </xsl:template>
  463. <xsl:template match="bibliography|glossary" mode="toc">
  464. <xsl:param name="toc-context" select="."/>
  465. <xsl:call-template name="subtoc">
  466. <xsl:with-param name="toc-context" select="$toc-context"/>
  467. </xsl:call-template>
  468. </xsl:template>
  469. <xsl:template match="index" mode="toc">
  470. <xsl:param name="toc-context" select="."/>
  471. <!-- If the index tag is not empty, it should be it in the TOC -->
  472. <xsl:if test="* or $generate.index != 0">
  473. <xsl:call-template name="subtoc">
  474. <xsl:with-param name="toc-context" select="$toc-context"/>
  475. </xsl:call-template>
  476. </xsl:if>
  477. </xsl:template>
  478. <xsl:template match="refentry" mode="toc">
  479. <xsl:param name="toc-context" select="."/>
  480. <xsl:variable name="refmeta" select=".//refmeta"/>
  481. <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
  482. <xsl:variable name="refnamediv" select=".//refnamediv"/>
  483. <xsl:variable name="refname" select="$refnamediv//refname"/>
  484. <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
  485. <xsl:variable name="title">
  486. <xsl:choose>
  487. <xsl:when test="$refentrytitle">
  488. <xsl:apply-templates select="$refentrytitle[1]"
  489. mode="titleabbrev.markup"/>
  490. </xsl:when>
  491. <xsl:when test="$refdesc">
  492. <xsl:apply-templates select="$refdesc"
  493. mode="titleabbrev.markup"/>
  494. </xsl:when>
  495. <xsl:when test="$refname">
  496. <xsl:apply-templates select="$refname[1]"
  497. mode="titleabbrev.markup"/>
  498. </xsl:when>
  499. </xsl:choose>
  500. </xsl:variable>
  501. <xsl:element name="{$toc.listitem.type}">
  502. <span class='refentrytitle'>
  503. <a>
  504. <xsl:attribute name="href">
  505. <xsl:call-template name="href.target">
  506. <xsl:with-param name="toc-context" select="$toc-context"/>
  507. </xsl:call-template>
  508. </xsl:attribute>
  509. <xsl:copy-of select="$title"/>
  510. </a>
  511. </span>
  512. <span class='refpurpose'>
  513. <xsl:if test="$annotate.toc != 0">
  514. <!-- * DocBook 5 says inlinemediaobject (among other things) -->
  515. <!-- * is allowed in refpurpose; so we need to run -->
  516. <!-- * apply-templates on refpurpose here, instead of value-of -->
  517. <xsl:apply-templates select="refnamediv/refpurpose" mode="no.anchor.mode"/>
  518. </xsl:if>
  519. </span>
  520. </xsl:element>
  521. </xsl:template>
  522. <xsl:template match="title" mode="toc">
  523. <xsl:param name="toc-context" select="."/>
  524. <a>
  525. <xsl:attribute name="href">
  526. <xsl:call-template name="href.target">
  527. <xsl:with-param name="object" select=".."/>
  528. <xsl:with-param name="toc-context" select="$toc-context"/>
  529. </xsl:call-template>
  530. </xsl:attribute>
  531. <xsl:apply-templates/>
  532. </a>
  533. </xsl:template>
  534. <xsl:template name="manual-toc">
  535. <xsl:param name="toc-context" select="."/>
  536. <xsl:param name="tocentry"/>
  537. <xsl:param name="toc.title.p" select="true()"/>
  538. <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  539. <!-- be careful, we don't want to change the current document to the other tree! -->
  540. <xsl:if test="$tocentry">
  541. <xsl:variable name="node" select="key('id', $tocentry/@linkend)"/>
  542. <xsl:element name="{$toc.listitem.type}">
  543. <xsl:variable name="label">
  544. <xsl:apply-templates select="$node" mode="label.markup"/>
  545. </xsl:variable>
  546. <xsl:copy-of select="$label"/>
  547. <xsl:if test="$label != ''">
  548. <xsl:value-of select="$autotoc.label.separator"/>
  549. </xsl:if>
  550. <a>
  551. <xsl:attribute name="href">
  552. <xsl:call-template name="href.target">
  553. <xsl:with-param name="object" select="$node"/>
  554. <xsl:with-param name="toc-context" select="$toc-context"/>
  555. </xsl:call-template>
  556. </xsl:attribute>
  557. <xsl:apply-templates select="$node" mode="titleabbrev.markup"/>
  558. </a>
  559. </xsl:element>
  560. <xsl:if test="$tocentry/*">
  561. <xsl:element name="{$toc.list.type}">
  562. <xsl:call-template name="toc.list.attributes">
  563. <xsl:with-param name="toc-context" select="$toc-context"/>
  564. <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
  565. <xsl:with-param name="nodes" select="$nodes"/>
  566. </xsl:call-template>
  567. <xsl:call-template name="manual-toc">
  568. <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
  569. </xsl:call-template>
  570. </xsl:element>
  571. </xsl:if>
  572. <xsl:if test="$tocentry/following-sibling::*">
  573. <xsl:call-template name="manual-toc">
  574. <xsl:with-param name="tocentry" select="$tocentry/following-sibling::*[1]"/>
  575. </xsl:call-template>
  576. </xsl:if>
  577. </xsl:if>
  578. </xsl:template>
  579. <!-- ==================================================================== -->
  580. <xsl:template name="list.of.titles">
  581. <xsl:param name="toc-context" select="."/>
  582. <xsl:param name="titles" select="'table'"/>
  583. <xsl:param name="nodes" select=".//table"/>
  584. <xsl:if test="$nodes">
  585. <div class="list-of-{$titles}s">
  586. <xsl:choose>
  587. <xsl:when test="$make.clean.html != 0">
  588. <div class="toc-title">
  589. <xsl:call-template name="gentext">
  590. <xsl:with-param name="key">
  591. <xsl:choose>
  592. <xsl:when test="$titles='table'">ListofTables</xsl:when>
  593. <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
  594. <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
  595. <xsl:when test="$titles='example'">ListofExamples</xsl:when>
  596. <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
  597. <xsl:otherwise>ListofUnknown</xsl:otherwise>
  598. </xsl:choose>
  599. </xsl:with-param>
  600. </xsl:call-template>
  601. </div>
  602. </xsl:when>
  603. <xsl:otherwise>
  604. <p>
  605. <b>
  606. <xsl:call-template name="gentext">
  607. <xsl:with-param name="key">
  608. <xsl:choose>
  609. <xsl:when test="$titles='table'">ListofTables</xsl:when>
  610. <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
  611. <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
  612. <xsl:when test="$titles='example'">ListofExamples</xsl:when>
  613. <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
  614. <xsl:otherwise>ListofUnknown</xsl:otherwise>
  615. </xsl:choose>
  616. </xsl:with-param>
  617. </xsl:call-template>
  618. </b>
  619. </p>
  620. </xsl:otherwise>
  621. </xsl:choose>
  622. <xsl:element name="{$toc.list.type}">
  623. <xsl:apply-templates select="$nodes" mode="toc">
  624. <xsl:with-param name="toc-context" select="$toc-context"/>
  625. </xsl:apply-templates>
  626. </xsl:element>
  627. </div>
  628. </xsl:if>
  629. </xsl:template>
  630. <xsl:template match="figure|table|example|equation|procedure" mode="toc">
  631. <xsl:param name="toc-context" select="."/>
  632. <xsl:element name="{$toc.listitem.type}">
  633. <xsl:variable name="label">
  634. <xsl:apply-templates select="." mode="label.markup"/>
  635. </xsl:variable>
  636. <xsl:copy-of select="$label"/>
  637. <xsl:if test="$label != ''">
  638. <xsl:value-of select="$autotoc.label.separator"/>
  639. </xsl:if>
  640. <a>
  641. <xsl:attribute name="href">
  642. <xsl:call-template name="href.target">
  643. <xsl:with-param name="toc-context" select="$toc-context"/>
  644. </xsl:call-template>
  645. </xsl:attribute>
  646. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  647. </a>
  648. </xsl:element>
  649. </xsl:template>
  650. <!-- Used only if qanda.in.toc parameter is non-zero -->
  651. <xsl:template match="qandaset" mode="toc">
  652. <xsl:param name="toc-context" select="."/>
  653. <xsl:call-template name="subtoc">
  654. <xsl:with-param name="toc-context" select="$toc-context"/>
  655. <xsl:with-param name="nodes" select="qandadiv | qandaentry"/>
  656. </xsl:call-template>
  657. </xsl:template>
  658. <xsl:template match="qandadiv|qandaentry" mode="toc">
  659. <xsl:apply-templates select="." mode="qandatoc.mode"/>
  660. </xsl:template>
  661. </xsl:stylesheet>