lfs-index.xsl 7.7 KB

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