autotoc.xsl 26 KB

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