toc.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?xml version="1.0" encoding="ASCII"?>
  2. <!--This file was created automatically by html2xhtml-->
  3. <!--from the HTML stylesheets.-->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
  5. <!-- ********************************************************************
  6. $Id: toc.xsl 9297 2012-04-22 03:56:16Z bobstayton $
  7. ********************************************************************
  8. This file is part of the XSL DocBook Stylesheet distribution.
  9. See ../README or http://docbook.sf.net/release/xsl/current/ for
  10. copyright and other information.
  11. ******************************************************************** -->
  12. <!-- ==================================================================== -->
  13. <xsl:template match="set/toc | book/toc | part/toc">
  14. <xsl:variable name="toc.params">
  15. <xsl:call-template name="find.path.params">
  16. <xsl:with-param name="node" select="parent::*"/>
  17. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  18. </xsl:call-template>
  19. </xsl:variable>
  20. <!-- Do not output the toc element if one is already generated
  21. by the use of $generate.toc parameter, or if
  22. generating a source toc is turned off -->
  23. <xsl:if test="not(contains($toc.params, 'toc')) and ($process.source.toc != 0 or $process.empty.source.toc != 0)">
  24. <xsl:variable name="content">
  25. <xsl:choose>
  26. <xsl:when test="* and $process.source.toc != 0">
  27. <xsl:apply-templates/>
  28. </xsl:when>
  29. <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
  30. <!-- trick to switch context node to parent element -->
  31. <xsl:for-each select="parent::*">
  32. <xsl:choose>
  33. <xsl:when test="self::set">
  34. <xsl:call-template name="set.toc">
  35. <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
  36. </xsl:call-template>
  37. </xsl:when>
  38. <xsl:when test="self::book">
  39. <xsl:call-template name="division.toc">
  40. <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
  41. </xsl:call-template>
  42. </xsl:when>
  43. <xsl:when test="self::part">
  44. <xsl:call-template name="division.toc">
  45. <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
  46. </xsl:call-template>
  47. </xsl:when>
  48. </xsl:choose>
  49. </xsl:for-each>
  50. </xsl:when>
  51. </xsl:choose>
  52. </xsl:variable>
  53. <xsl:if test="string-length(normalize-space($content)) != 0">
  54. <xsl:copy-of select="$content"/>
  55. </xsl:if>
  56. </xsl:if>
  57. </xsl:template>
  58. <xsl:template match="chapter/toc | appendix/toc | preface/toc | article/toc">
  59. <xsl:variable name="toc.params">
  60. <xsl:call-template name="find.path.params">
  61. <xsl:with-param name="node" select="parent::*"/>
  62. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  63. </xsl:call-template>
  64. </xsl:variable>
  65. <!-- Do not output the toc element if one is already generated
  66. by the use of $generate.toc parameter, or if
  67. generating a source toc is turned off -->
  68. <xsl:if test="not(contains($toc.params, 'toc')) and ($process.source.toc != 0 or $process.empty.source.toc != 0)">
  69. <xsl:choose>
  70. <xsl:when test="* and $process.source.toc != 0">
  71. <div>
  72. <xsl:apply-templates select="." mode="common.html.attributes"/>
  73. <xsl:call-template name="id.attribute"/>
  74. <xsl:apply-templates select="title"/>
  75. <dl>
  76. <xsl:apply-templates select="." mode="common.html.attributes"/>
  77. <xsl:apply-templates select="*[not(self::title)]"/>
  78. </dl>
  79. </div>
  80. <xsl:call-template name="component.toc.separator"/>
  81. </xsl:when>
  82. <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
  83. <!-- trick to switch context node to section element -->
  84. <xsl:for-each select="parent::*">
  85. <xsl:call-template name="component.toc">
  86. <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
  87. </xsl:call-template>
  88. </xsl:for-each>
  89. <xsl:call-template name="component.toc.separator"/>
  90. </xsl:when>
  91. </xsl:choose>
  92. </xsl:if>
  93. </xsl:template>
  94. <xsl:template match="section/toc |sect1/toc |sect2/toc |sect3/toc |sect4/toc |sect5/toc">
  95. <xsl:variable name="toc.params">
  96. <xsl:call-template name="find.path.params">
  97. <xsl:with-param name="node" select="parent::*"/>
  98. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  99. </xsl:call-template>
  100. </xsl:variable>
  101. <!-- Do not output the toc element if one is already generated
  102. by the use of $generate.toc parameter, or if
  103. generating a source toc is turned off -->
  104. <xsl:if test="not(contains($toc.params, 'toc')) and ($process.source.toc != 0 or $process.empty.source.toc != 0)">
  105. <xsl:choose>
  106. <xsl:when test="* and $process.source.toc != 0">
  107. <div>
  108. <xsl:apply-templates select="." mode="common.html.attributes"/>
  109. <xsl:call-template name="id.attribute"/>
  110. <xsl:apply-templates select="title"/>
  111. <dl>
  112. <xsl:apply-templates select="." mode="common.html.attributes"/>
  113. <xsl:apply-templates select="*[not(self::title)]"/>
  114. </dl>
  115. </div>
  116. <xsl:call-template name="section.toc.separator"/>
  117. </xsl:when>
  118. <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
  119. <!-- trick to switch context node to section element -->
  120. <xsl:for-each select="parent::*">
  121. <xsl:call-template name="section.toc">
  122. <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
  123. </xsl:call-template>
  124. </xsl:for-each>
  125. <xsl:call-template name="section.toc.separator"/>
  126. </xsl:when>
  127. </xsl:choose>
  128. </xsl:if>
  129. </xsl:template>
  130. <!-- ==================================================================== -->
  131. <xsl:template match="tocpart|tocchap |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
  132. <xsl:variable name="sub-toc">
  133. <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
  134. <xsl:choose>
  135. <xsl:when test="$toc.list.type = 'dl'">
  136. <dd>
  137. <xsl:apply-templates select="." mode="common.html.attributes"/>
  138. <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
  139. <xsl:apply-templates select="." mode="common.html.attributes"/>
  140. <xsl:apply-templates select="tocchap|toclevel1|toclevel2| toclevel3|toclevel4|toclevel5"/>
  141. </xsl:element>
  142. </dd>
  143. </xsl:when>
  144. <xsl:otherwise>
  145. <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
  146. <xsl:apply-templates select="." mode="common.html.attributes"/>
  147. <xsl:apply-templates select="tocchap|toclevel1|toclevel2| toclevel3|toclevel4|toclevel5"/>
  148. </xsl:element>
  149. </xsl:otherwise>
  150. </xsl:choose>
  151. </xsl:if>
  152. </xsl:variable>
  153. <xsl:apply-templates select="tocentry[position() != last()]"/>
  154. <xsl:choose>
  155. <xsl:when test="$toc.list.type = 'dl'">
  156. <dt>
  157. <xsl:apply-templates select="." mode="common.html.attributes"/>
  158. <xsl:apply-templates select="tocentry[position() = last()]"/>
  159. </dt>
  160. <xsl:copy-of select="$sub-toc"/>
  161. </xsl:when>
  162. <xsl:otherwise>
  163. <li>
  164. <xsl:apply-templates select="." mode="common.html.attributes"/>
  165. <xsl:apply-templates select="tocentry[position() = last()]"/>
  166. <xsl:copy-of select="$sub-toc"/>
  167. </li>
  168. </xsl:otherwise>
  169. </xsl:choose>
  170. </xsl:template>
  171. <xsl:template match="tocentry|tocdiv|lotentry|tocfront|tocback">
  172. <xsl:choose>
  173. <xsl:when test="$toc.list.type = 'dl'">
  174. <dt>
  175. <xsl:apply-templates select="." mode="common.html.attributes"/>
  176. <xsl:call-template name="tocentry-content"/>
  177. </dt>
  178. </xsl:when>
  179. <xsl:otherwise>
  180. <li>
  181. <xsl:apply-templates select="." mode="common.html.attributes"/>
  182. <xsl:call-template name="tocentry-content"/>
  183. </li>
  184. </xsl:otherwise>
  185. </xsl:choose>
  186. </xsl:template>
  187. <xsl:template match="tocentry[position() = last()]" priority="2">
  188. <xsl:call-template name="tocentry-content"/>
  189. </xsl:template>
  190. <xsl:template name="tocentry-content">
  191. <xsl:variable name="targets" select="key('id',@linkend)"/>
  192. <xsl:variable name="target" select="$targets[1]"/>
  193. <xsl:choose>
  194. <xsl:when test="@linkend">
  195. <xsl:call-template name="check.id.unique">
  196. <xsl:with-param name="linkend" select="@linkend"/>
  197. </xsl:call-template>
  198. <a>
  199. <xsl:attribute name="href">
  200. <xsl:call-template name="href.target">
  201. <xsl:with-param name="object" select="$target"/>
  202. </xsl:call-template>
  203. </xsl:attribute>
  204. <xsl:apply-templates/>
  205. </a>
  206. </xsl:when>
  207. <xsl:otherwise>
  208. <xsl:apply-templates/>
  209. </xsl:otherwise>
  210. </xsl:choose>
  211. </xsl:template>
  212. <xsl:template match="toc/title">
  213. <div>
  214. <xsl:apply-templates select="." mode="common.html.attributes"/>
  215. <xsl:apply-templates/>
  216. </div>
  217. </xsl:template>
  218. <xsl:template match="toc/subtitle">
  219. <div>
  220. <xsl:apply-templates select="." mode="common.html.attributes"/>
  221. <xsl:apply-templates/>
  222. </div>
  223. </xsl:template>
  224. <xsl:template match="toc/titleabbrev">
  225. </xsl:template>
  226. <!-- ==================================================================== -->
  227. <!-- A lot element must have content, because there is no attribute
  228. to select what kind of list should be generated -->
  229. <xsl:template match="book/lot | part/lot">
  230. <!-- Don't generate a page sequence unless there is content -->
  231. <xsl:variable name="content">
  232. <xsl:choose>
  233. <xsl:when test="* and $process.source.toc != 0">
  234. <div>
  235. <xsl:apply-templates select="." mode="common.html.attributes"/>
  236. <xsl:apply-templates/>
  237. </div>
  238. </xsl:when>
  239. <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
  240. <xsl:call-template name="process.empty.lot"/>
  241. </xsl:when>
  242. </xsl:choose>
  243. </xsl:variable>
  244. <xsl:if test="string-length(normalize-space($content)) != 0">
  245. <xsl:copy-of select="$content"/>
  246. </xsl:if>
  247. </xsl:template>
  248. <xsl:template match="chapter/lot | appendix/lot | preface/lot | article/lot">
  249. <xsl:choose>
  250. <xsl:when test="* and $process.source.toc != 0">
  251. <div>
  252. <xsl:apply-templates select="." mode="common.html.attributes"/>
  253. <xsl:apply-templates/>
  254. </div>
  255. <xsl:call-template name="component.toc.separator"/>
  256. </xsl:when>
  257. <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
  258. <xsl:call-template name="process.empty.lot"/>
  259. </xsl:when>
  260. </xsl:choose>
  261. </xsl:template>
  262. <xsl:template match="section/lot |sect1/lot |sect2/lot |sect3/lot |sect4/lot |sect5/lot">
  263. <xsl:choose>
  264. <xsl:when test="* and $process.source.toc != 0">
  265. <div>
  266. <xsl:apply-templates select="." mode="common.html.attributes"/>
  267. <xsl:apply-templates/>
  268. </div>
  269. <xsl:call-template name="section.toc.separator"/>
  270. </xsl:when>
  271. <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
  272. <xsl:call-template name="process.empty.lot"/>
  273. </xsl:when>
  274. </xsl:choose>
  275. </xsl:template>
  276. <xsl:template name="process.empty.lot">
  277. <!-- An empty lot element does not provide any information to indicate
  278. what should be included in it. You can customize this
  279. template to generate a lot based on @role or something -->
  280. <xsl:message>
  281. <xsl:text>Warning: don't know what to generate for </xsl:text>
  282. <xsl:text>lot that has no children.</xsl:text>
  283. </xsl:message>
  284. </xsl:template>
  285. <xsl:template match="lot/title">
  286. <div>
  287. <xsl:apply-templates select="." mode="common.html.attributes"/>
  288. <xsl:apply-templates/>
  289. </div>
  290. </xsl:template>
  291. <xsl:template match="lot/subtitle">
  292. <div>
  293. <xsl:apply-templates select="." mode="common.html.attributes"/>
  294. <xsl:apply-templates/>
  295. </div>
  296. </xsl:template>
  297. <xsl:template match="lot/titleabbrev">
  298. </xsl:template>
  299. </xsl:stylesheet>