lfs-toc.xsl 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns="http://www.w3.org/1999/xhtml"
  4. version="1.0">
  5. <!-- This stylesheet controls how the TOC are generated -->
  6. <!-- Control generation of ToCs and LoTs -->
  7. <xsl:param name="generate.toc">
  8. book toc,title
  9. preface toc
  10. part toc
  11. chapter toc
  12. appendix nop
  13. sect1 nop
  14. sect2 nop
  15. sect3 nop
  16. sect4 nop
  17. sect5 nop
  18. section nop
  19. </xsl:param>
  20. <!-- How deep should recursive sections appear in the TOC? -->
  21. <xsl:param name="toc.section.depth">1</xsl:param>
  22. <!-- How maximaly deep should be each TOC? -->
  23. <xsl:param name="toc.max.depth">3</xsl:param>
  24. <!-- make.toc:
  25. Using h3 for TOC title.
  26. Using ul for TOC list style.
  27. Removed code for $manual.toc and $qanda.in.toc -->
  28. <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  29. <xsl:template name="make.toc">
  30. <xsl:param name="toc-context" select="."/>
  31. <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  32. <xsl:if test="$nodes">
  33. <div class="toc">
  34. <h3>
  35. <xsl:call-template name="gentext">
  36. <xsl:with-param name="key">TableofContents</xsl:with-param>
  37. </xsl:call-template>
  38. </h3>
  39. <ul>
  40. <xsl:apply-templates select="$nodes" mode="toc">
  41. <xsl:with-param name="toc-context" select="$toc-context"/>
  42. </xsl:apply-templates>
  43. </ul>
  44. </div>
  45. </xsl:if>
  46. </xsl:template>
  47. <!-- subtoc:
  48. Using ul for TOC list style.
  49. Removed code for $qanda.in.toc
  50. Removed code for sect* others than sect1 -->
  51. <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  52. <xsl:template name="subtoc">
  53. <xsl:param name="toc-context" select="."/>
  54. <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
  55. <xsl:variable name="subtoc">
  56. <ul>
  57. <xsl:apply-templates mode="toc" select="$nodes">
  58. <xsl:with-param name="toc-context" select="$toc-context"/>
  59. </xsl:apply-templates>
  60. </ul>
  61. </xsl:variable>
  62. <xsl:variable name="depth">
  63. <xsl:choose>
  64. <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
  65. <xsl:otherwise>0</xsl:otherwise>
  66. </xsl:choose>
  67. </xsl:variable>
  68. <xsl:variable name="depth.from.context"
  69. select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
  70. <li class="{name(.)}">
  71. <xsl:call-template name="toc.line">
  72. <xsl:with-param name="toc-context" select="$toc-context"/>
  73. </xsl:call-template>
  74. <xsl:if test="$toc.section.depth &gt; $depth and count($nodes)&gt;0
  75. and $toc.max.depth &gt; $depth.from.context">
  76. <xsl:copy-of select="$subtoc"/>
  77. </xsl:if>
  78. </li>
  79. </xsl:template>
  80. <!-- toc.line:
  81. Adding the h* tags and dropping redundats links.
  82. This template is a full re-made version of the original one. -->
  83. <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  84. <xsl:template name="toc.line">
  85. <xsl:param name="toc-context" select="."/>
  86. <xsl:param name="depth" select="1"/>
  87. <xsl:param name="depth.from.context" select="8"/>
  88. <xsl:choose>
  89. <!-- For sect1 targets, create a link -->
  90. <xsl:when test="local-name(.) = 'sect1'">
  91. <a>
  92. <xsl:attribute name="href">
  93. <xsl:call-template name="href.target">
  94. <xsl:with-param name="context" select="$toc-context"/>
  95. </xsl:call-template>
  96. </xsl:attribute>
  97. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  98. </a>
  99. </xsl:when>
  100. <!-- For appendix target, create a link and add the label -->
  101. <xsl:when test="local-name(.) = 'appendix'">
  102. <a>
  103. <xsl:attribute name="href">
  104. <xsl:call-template name="href.target">
  105. <xsl:with-param name="context" select="$toc-context"/>
  106. </xsl:call-template>
  107. </xsl:attribute>
  108. <xsl:variable name="label">
  109. <xsl:apply-templates select="." mode="label.markup"/>
  110. </xsl:variable>
  111. <xsl:copy-of select="$label"/>
  112. <xsl:if test="$label != ''">
  113. <xsl:value-of select="$autotoc.label.separator"/>
  114. </xsl:if>
  115. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  116. </a>
  117. </xsl:when>
  118. <!-- For chapter and preface, use h4 and add the label -->
  119. <xsl:when test="local-name(.) = 'chapter' or local-name(.) = 'preface'">
  120. <h4>
  121. <xsl:variable name="label">
  122. <xsl:apply-templates select="." mode="label.markup"/>
  123. </xsl:variable>
  124. <xsl:copy-of select="$label"/>
  125. <xsl:if test="$label != ''">
  126. <xsl:value-of select="$autotoc.label.separator"/>
  127. </xsl:if>
  128. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  129. </h4>
  130. </xsl:when>
  131. <!-- for part, use h3 and add the label -->
  132. <xsl:when test="local-name(.) = 'part'">
  133. <h3>
  134. <xsl:variable name="label">
  135. <xsl:apply-templates select="." mode="label.markup"/>
  136. </xsl:variable>
  137. <xsl:copy-of select="$label"/>
  138. <xsl:if test="$label != ''">
  139. <xsl:value-of select="$autotoc.label.separator"/>
  140. </xsl:if>
  141. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  142. </h3>
  143. </xsl:when>
  144. <!-- For other targets like Index, create a link inside h3 plus label it -->
  145. <xsl:otherwise>
  146. <h3>
  147. <a>
  148. <xsl:attribute name="href">
  149. <xsl:call-template name="href.target">
  150. <xsl:with-param name="context" select="$toc-context"/>
  151. </xsl:call-template>
  152. </xsl:attribute>
  153. <xsl:variable name="label">
  154. <xsl:apply-templates select="." mode="label.markup"/>
  155. </xsl:variable>
  156. <xsl:copy-of select="$label"/>
  157. <xsl:if test="$label != ''">
  158. <xsl:value-of select="$autotoc.label.separator"/>
  159. </xsl:if>
  160. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  161. </a>
  162. </h3>
  163. </xsl:otherwise>
  164. </xsl:choose>
  165. </xsl:template>
  166. </xsl:stylesheet>