lfs-index.xsl 7.4 KB

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