autotoc.xsl 32 KB

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