lfs-index.xsl 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
  4. <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
  5. <!ENTITY primary 'normalize-space(concat(primary/@sortas, primary[not(@sortas)]))'>
  6. <!ENTITY scope 'count(ancestor::node()|$scope) = count(ancestor::node())'>
  7. ]>
  8. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  9. xmlns="http://www.w3.org/1999/xhtml"
  10. version="1.0">
  11. <!-- This stylesheet controls how the Index is generated -->
  12. <!-- Should the Index be generated? 1 = yes, 0 = no -->
  13. <xsl:param name="generate.index" select="1"></xsl:param>
  14. <!-- The indexing method used. Only 'basic' is supported by xsltproc -->
  15. <xsl:param name="index.method" select="'basic'"></xsl:param>
  16. <!--The file name of the Index page -->
  17. <xsl:template match="index" mode="recursive-chunk-filename">
  18. <xsl:text>longindex.html</xsl:text>
  19. </xsl:template>
  20. <!--Title-->
  21. <xsl:param name="index-title">Index</xsl:param>
  22. <xsl:template match="index" mode="title.markup">
  23. <xsl:call-template name="gentext">
  24. <xsl:with-param name="key" select="$index-title"/>
  25. </xsl:call-template>
  26. </xsl:template>
  27. <xsl:template name="index.titlepage">
  28. <div class="titlepage">
  29. <h1 class="index">
  30. <xsl:call-template name="gentext">
  31. <xsl:with-param name="key" select="$index-title"/>
  32. </xsl:call-template>
  33. </h1>
  34. </div>
  35. </xsl:template>
  36. <!--Divisions-->
  37. <xsl:template match="indexterm" mode="index-div">
  38. <xsl:param name="scope" select="."/>
  39. <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  40. <xsl:variable name="divtitle" select="translate($key, &lowercase;, &uppercase;)"/>
  41. <!-- Make sure that we don't generate a div if there are no terms in scope -->
  42. <xsl:if test="key('letter', $key)[&scope;] [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  43. <div class="indexdiv">
  44. <xsl:if test="contains(concat(&lowercase;, &uppercase;), $key)">
  45. <h2>
  46. <xsl:choose>
  47. <xsl:when test="$divtitle = 'A'">
  48. <xsl:call-template name="gentext">
  49. <xsl:with-param name="key">Packages</xsl:with-param>
  50. </xsl:call-template>
  51. </xsl:when>
  52. <xsl:when test="$divtitle = 'B'">
  53. <xsl:call-template name="gentext">
  54. <xsl:with-param name="key">Programs</xsl:with-param>
  55. </xsl:call-template>
  56. </xsl:when>
  57. <xsl:when test="$divtitle = 'C'">
  58. <xsl:call-template name="gentext">
  59. <xsl:with-param name="key">Libraries</xsl:with-param>
  60. </xsl:call-template>
  61. </xsl:when>
  62. <xsl:when test="$divtitle = 'D'">
  63. <xsl:call-template name="gentext">
  64. <xsl:with-param name="key">Scripts</xsl:with-param>
  65. </xsl:call-template>
  66. </xsl:when>
  67. <xsl:when test="$divtitle = 'E'">
  68. <xsl:call-template name="gentext">
  69. <xsl:with-param name="key">Others</xsl:with-param>
  70. </xsl:call-template>
  71. </xsl:when>
  72. <xsl:otherwise>
  73. <xsl:value-of select="$divtitle"/>
  74. </xsl:otherwise>
  75. </xsl:choose>
  76. </h2>
  77. </xsl:if>
  78. <ul>
  79. <xsl:apply-templates select="key('letter', $key)[&scope;]
  80. [count(.|key('primary', &primary;)[&scope;][1])=1]" mode="index-primary">
  81. <xsl:with-param name="scope" select="$scope"/>
  82. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  83. </xsl:apply-templates>
  84. </ul>
  85. </div>
  86. </xsl:if>
  87. </xsl:template>
  88. <!-- Dropping the separator from here-->
  89. <xsl:template match="indexterm" mode="reference">
  90. <xsl:param name="scope" select="."/>
  91. <xsl:call-template name="reference">
  92. <xsl:with-param name="zones" select="normalize-space(@zone)"/>
  93. <xsl:with-param name="scope" select="$scope"/>
  94. </xsl:call-template>
  95. </xsl:template>
  96. <!-- Changing the output tags and re-addind the separator-->
  97. <xsl:template match="indexterm" mode="index-primary">
  98. <xsl:param name="scope" select="."/>
  99. <xsl:variable name="key" select="&primary;"/>
  100. <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
  101. <li>
  102. <strong class="item">
  103. <xsl:value-of select="primary"/>
  104. <xsl:text>: </xsl:text>
  105. </strong>
  106. <xsl:for-each select="$refs[generate-id() = generate-id(key('primary-section',
  107. concat($key, &#34; &#34;, generate-id((ancestor-or-self::book |ancestor-or-self::part
  108. |ancestor-or-self::chapter |ancestor-or-self::appendix |ancestor-or-self::preface
  109. |ancestor-or-self::sect1 |ancestor-or-self::sect2 |ancestor-or-self::sect3
  110. |ancestor-or-self::sect4 |ancestor-or-self::sect5 |ancestor-or-self::index)[last()])))[&scope;][1])]">
  111. <xsl:apply-templates select="." mode="reference">
  112. <xsl:with-param name="scope" select="$scope"/>
  113. </xsl:apply-templates>
  114. </xsl:for-each>
  115. <xsl:if test="$refs/secondary">
  116. <ul>
  117. <xsl:apply-templates select="$refs[secondary and count(.|key('secondary',
  118. concat($key, &#34; &#34;, normalize-space(concat(secondary/@sortas,
  119. secondary[not(@sortas)]))))[&scope;][1]) = 1]" mode="index-secondary">
  120. <xsl:with-param name="scope" select="$scope"/>
  121. <xsl:sort select="translate(normalize-space(concat(secondary/@sortas,
  122. secondary[not(@sortas)])), &lowercase;, &uppercase;)"/>
  123. </xsl:apply-templates>
  124. </ul>
  125. </xsl:if>
  126. </li>
  127. </xsl:template>
  128. <xsl:template match="indexterm" mode="index-secondary">
  129. <xsl:param name="scope" select="."/>
  130. <xsl:variable name="key" select="concat(&primary;, &#34; &#34;,
  131. normalize-space(concat(secondary/@sortas, secondary[not(@sortas)])))"/>
  132. <xsl:variable name="refs" select="key('secondary', $key)[&scope;]"/>
  133. <li>
  134. <strong class="secitem">
  135. <xsl:value-of select="secondary"/>
  136. <xsl:text>: </xsl:text>
  137. </strong>
  138. <xsl:for-each select="$refs[generate-id() = generate-id(key('secondary-section',
  139. concat($key, &#34; &#34;, generate-id((ancestor-or-self::book |ancestor-or-self::part
  140. |ancestor-or-self::chapter |ancestor-or-self::appendix |ancestor-or-self::preface
  141. |ancestor-or-self::sect1 |ancestor-or-self::sect2 |ancestor-or-self::sect3
  142. |ancestor-or-self::sect4 |ancestor-or-self::sect5 |ancestor-or-self::index)[last()])))[&scope;][1])]">
  143. <xsl:apply-templates select="." mode="reference">
  144. <xsl:with-param name="scope" select="$scope"/>
  145. </xsl:apply-templates>
  146. </xsl:for-each>
  147. </li>
  148. </xsl:template>
  149. <!--Links (This template also fix a bug in the original code)-->
  150. <xsl:template name="reference">
  151. <xsl:param name="scope" select="."/>
  152. <xsl:param name="zones"/>
  153. <xsl:choose>
  154. <xsl:when test="contains($zones, ' ')">
  155. <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
  156. <xsl:variable name="zone2" select="substring-after($zones, ' ')"/>
  157. <xsl:variable name="target" select="key('sections', $zone)[&scope;]"/>
  158. <xsl:variable name="target2" select="key('sections', $zone2)[&scope;]"/>
  159. <a>
  160. <xsl:attribute name="href">
  161. <xsl:call-template name="href.target.uri">
  162. <xsl:with-param name="object" select="$target[1]"/>
  163. </xsl:call-template>
  164. </xsl:attribute>
  165. <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
  166. </a>
  167. <xsl:text> -- </xsl:text>
  168. <a>
  169. <xsl:attribute name="href">
  170. <xsl:call-template name="href.target.uri">
  171. <xsl:with-param name="object" select="$target2[1]"/>
  172. </xsl:call-template>
  173. </xsl:attribute>
  174. <xsl:call-template name="gentext">
  175. <xsl:with-param name="key">description</xsl:with-param>
  176. </xsl:call-template>
  177. </a>
  178. </xsl:when>
  179. <xsl:otherwise>
  180. <xsl:variable name="zone" select="$zones"/>
  181. <xsl:variable name="target" select="key('sections', $zone)[&scope;]"/>
  182. <a>
  183. <xsl:attribute name="href">
  184. <xsl:call-template name="href.target.uri">
  185. <xsl:with-param name="object" select="$target[1]"/>
  186. </xsl:call-template>
  187. </xsl:attribute>
  188. <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
  189. </a>
  190. </xsl:otherwise>
  191. </xsl:choose>
  192. </xsl:template>
  193. <!-- Dropping unneeded anchors -->
  194. <xsl:template match="indexterm"/>
  195. </xsl:stylesheet>