lfs-index.xsl 8.4 KB

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