lfs-toc.xsl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. <!-- General settings -->
  6. <xsl:param name="generate.toc">
  7. appendix nop
  8. book toc,title
  9. chapter nop
  10. part toc
  11. preface nop
  12. qandadiv nop
  13. qandaset nop
  14. reference nop
  15. sect1 nop
  16. sect2 nop
  17. sect3 nop
  18. sect4 nop
  19. sect5 nop
  20. section nop
  21. set nop
  22. </xsl:param>
  23. <xsl:param name="toc.section.depth">1</xsl:param>
  24. <xsl:param name="toc.max.depth">3</xsl:param>
  25. <!-- Making the TOC -->
  26. <xsl:template name="make.toc">
  27. <xsl:param name="toc-context" select="."/>
  28. <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  29. <xsl:if test="$nodes">
  30. <div class="toc">
  31. <h3>
  32. <xsl:call-template name="gentext">
  33. <xsl:with-param name="key">TableofContents</xsl:with-param>
  34. </xsl:call-template>
  35. </h3>
  36. <ul>
  37. <xsl:apply-templates select="$nodes" mode="toc">
  38. <xsl:with-param name="toc-context" select="$toc-context"/>
  39. </xsl:apply-templates>
  40. </ul>
  41. </div>
  42. </xsl:if>
  43. </xsl:template>
  44. <!-- Making the subtocs -->
  45. <xsl:template name="subtoc">
  46. <xsl:param name="toc-context" select="."/>
  47. <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
  48. <xsl:variable name="subtoc">
  49. <ul>
  50. <xsl:apply-templates mode="toc" select="$nodes">
  51. <xsl:with-param name="toc-context" select="$toc-context"/>
  52. </xsl:apply-templates>
  53. </ul>
  54. </xsl:variable>
  55. <xsl:variable name="depth">
  56. <xsl:choose>
  57. <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
  58. <xsl:otherwise>0</xsl:otherwise>
  59. </xsl:choose>
  60. </xsl:variable>
  61. <xsl:variable name="depth.from.context"
  62. select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
  63. <li class="{name(.)}">
  64. <xsl:call-template name="toc.line">
  65. <xsl:with-param name="toc-context" select="$toc-context"/>
  66. </xsl:call-template>
  67. <xsl:if test="$toc.section.depth &gt; $depth and count($nodes)&gt;0
  68. and $toc.max.depth &gt; $depth.from.context">
  69. <xsl:copy-of select="$subtoc"/>
  70. </xsl:if>
  71. </li>
  72. </xsl:template>
  73. <!--Adding the h* tags and dropping redundats links-->
  74. <xsl:template name="toc.line">
  75. <xsl:param name="toc-context" select="."/>
  76. <xsl:param name="depth" select="1"/>
  77. <xsl:param name="depth.from.context" select="8"/>
  78. <xsl:choose>
  79. <xsl:when test="local-name(.) = 'sect1'">
  80. <a>
  81. <xsl:attribute name="href">
  82. <xsl:call-template name="href.target">
  83. <xsl:with-param name="context" select="$toc-context"/>
  84. </xsl:call-template>
  85. </xsl:attribute>
  86. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  87. </a>
  88. </xsl:when>
  89. <xsl:when test="local-name(.) = 'appendix'">
  90. <a>
  91. <xsl:attribute name="href">
  92. <xsl:call-template name="href.target">
  93. <xsl:with-param name="context" select="$toc-context"/>
  94. </xsl:call-template>
  95. </xsl:attribute>
  96. <xsl:variable name="label">
  97. <xsl:apply-templates select="." mode="label.markup"/>
  98. </xsl:variable>
  99. <xsl:copy-of select="$label"/>
  100. <xsl:if test="$label != ''">
  101. <xsl:value-of select="$autotoc.label.separator"/>
  102. </xsl:if>
  103. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  104. </a>
  105. </xsl:when>
  106. <xsl:when test="local-name(.) = 'chapter' or local-name(.) = 'preface'">
  107. <h4>
  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. </h4>
  117. </xsl:when>
  118. <xsl:when test="local-name(.) = 'part'">
  119. <h3>
  120. <xsl:variable name="label">
  121. <xsl:apply-templates select="." mode="label.markup"/>
  122. </xsl:variable>
  123. <xsl:copy-of select="$label"/>
  124. <xsl:if test="$label != ''">
  125. <xsl:value-of select="$autotoc.label.separator"/>
  126. </xsl:if>
  127. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  128. </h3>
  129. </xsl:when>
  130. <xsl:otherwise>
  131. <h3>
  132. <a>
  133. <xsl:attribute name="href">
  134. <xsl:call-template name="href.target">
  135. <xsl:with-param name="context" select="$toc-context"/>
  136. </xsl:call-template>
  137. </xsl:attribute>
  138. <xsl:variable name="label">
  139. <xsl:apply-templates select="." mode="label.markup"/>
  140. </xsl:variable>
  141. <xsl:copy-of select="$label"/>
  142. <xsl:if test="$label != ''">
  143. <xsl:value-of select="$autotoc.label.separator"/>
  144. </xsl:if>
  145. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  146. </a>
  147. </h3>
  148. </xsl:otherwise>
  149. </xsl:choose>
  150. </xsl:template>
  151. </xsl:stylesheet>