autotoc.xsl 28 KB

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