lfs-toc.xsl 5.8 KB

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