lfs-index.xsl 7.7 KB

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