autotoc.xsl 28 KB

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