You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

toc.xsl 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. version='1.0'>
  4. <!-- ********************************************************************
  5. $Id: toc.xsl,v 1.1 2002/05/15 17:22:30 isberg Exp $
  6. ********************************************************************
  7. This file is part of the XSL DocBook Stylesheet distribution.
  8. See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  9. and other information.
  10. ******************************************************************** -->
  11. <!-- ==================================================================== -->
  12. <xsl:template match="toc">
  13. <xsl:choose>
  14. <xsl:when test="*">
  15. <xsl:if test="$process.source.toc != 0">
  16. <!-- if the toc isn't empty, process it -->
  17. <xsl:element name="{$toc.list.type}">
  18. <xsl:apply-templates/>
  19. </xsl:element>
  20. </xsl:if>
  21. </xsl:when>
  22. <xsl:otherwise>
  23. <xsl:if test="$process.empty.source.toc != 0">
  24. <xsl:choose>
  25. <xsl:when test="parent::section
  26. or parent::sect1
  27. or parent::sect2
  28. or parent::sect3
  29. or parent::sect4
  30. or parent::sect5">
  31. <xsl:apply-templates select="parent::*"
  32. mode="toc.for.section"/>
  33. </xsl:when>
  34. <xsl:when test="parent::article">
  35. <xsl:apply-templates select="parent::*"
  36. mode="toc.for.component"/>
  37. </xsl:when>
  38. <xsl:when test="parent::book
  39. or parent::part">
  40. <xsl:apply-templates select="parent::*"
  41. mode="toc.for.division"/>
  42. </xsl:when>
  43. <xsl:when test="parent::set">
  44. <xsl:apply-templates select="parent::*"
  45. mode="toc.for.set"/>
  46. </xsl:when>
  47. <!-- there aren't any other contexts that allow toc -->
  48. <xsl:otherwise>
  49. <xsl:message>
  50. <xsl:text>I don't know how to make a TOC in this context!</xsl:text>
  51. </xsl:message>
  52. </xsl:otherwise>
  53. </xsl:choose>
  54. </xsl:if>
  55. </xsl:otherwise>
  56. </xsl:choose>
  57. </xsl:template>
  58. <xsl:template match="tocpart|tocchap
  59. |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
  60. <xsl:variable name="sub-toc">
  61. <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
  62. <xsl:choose>
  63. <xsl:when test="$toc.list.type = 'dl'">
  64. <dd>
  65. <xsl:element name="{$toc.list.type}">
  66. <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
  67. </xsl:element>
  68. </dd>
  69. </xsl:when>
  70. <xsl:otherwise>
  71. <xsl:element name="{$toc.list.type}">
  72. <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
  73. </xsl:element>
  74. </xsl:otherwise>
  75. </xsl:choose>
  76. </xsl:if>
  77. </xsl:variable>
  78. <xsl:apply-templates select="tocentry[position() != last()]"/>
  79. <xsl:choose>
  80. <xsl:when test="$toc.list.type = 'dl'">
  81. <dt>
  82. <xsl:apply-templates select="tocentry[position() = last()]"/>
  83. </dt>
  84. <xsl:copy-of select="$sub-toc"/>
  85. </xsl:when>
  86. <xsl:otherwise>
  87. <li>
  88. <xsl:apply-templates select="tocentry[position() = last()]"/>
  89. <xsl:copy-of select="$sub-toc"/>
  90. </li>
  91. </xsl:otherwise>
  92. </xsl:choose>
  93. </xsl:template>
  94. <xsl:template match="tocentry|tocfront|tocback">
  95. <xsl:choose>
  96. <xsl:when test="$toc.list.type = 'dl'">
  97. <dt>
  98. <xsl:call-template name="tocentry-content"/>
  99. </dt>
  100. </xsl:when>
  101. <xsl:otherwise>
  102. <li>
  103. <xsl:call-template name="tocentry-content"/>
  104. </li>
  105. </xsl:otherwise>
  106. </xsl:choose>
  107. </xsl:template>
  108. <xsl:template match="tocentry[position() = last()]" priority="2">
  109. <xsl:call-template name="tocentry-content"/>
  110. </xsl:template>
  111. <xsl:template name="tocentry-content">
  112. <xsl:variable name="targets" select="id(@linkend)"/>
  113. <xsl:variable name="target" select="$targets[1]"/>
  114. <xsl:choose>
  115. <xsl:when test="@linkend">
  116. <xsl:call-template name="check.id.unique">
  117. <xsl:with-param name="linkend" select="@linkend"/>
  118. </xsl:call-template>
  119. <a>
  120. <xsl:attribute name="href">
  121. <xsl:call-template name="href.target">
  122. <xsl:with-param name="object" select="$target"/>
  123. </xsl:call-template>
  124. </xsl:attribute>
  125. <xsl:apply-templates/>
  126. </a>
  127. </xsl:when>
  128. <xsl:otherwise>
  129. <xsl:apply-templates/>
  130. </xsl:otherwise>
  131. </xsl:choose>
  132. </xsl:template>
  133. <!-- ==================================================================== -->
  134. <xsl:template match="*" mode="toc.for.section">
  135. <xsl:call-template name="section.toc"/>
  136. </xsl:template>
  137. <xsl:template match="*" mode="toc.for.component">
  138. <xsl:call-template name="component.toc"/>
  139. </xsl:template>
  140. <xsl:template match="*" mode="toc.for.section">
  141. <xsl:call-template name="section.toc"/>
  142. </xsl:template>
  143. <xsl:template match="*" mode="toc.for.division">
  144. <xsl:call-template name="division.toc"/>
  145. </xsl:template>
  146. <xsl:template match="*" mode="toc.for.set">
  147. <xsl:call-template name="set.toc"/>
  148. </xsl:template>
  149. <!-- ==================================================================== -->
  150. <xsl:template match="lot|lotentry">
  151. </xsl:template>
  152. </xsl:stylesheet>