lfs-index.xsl 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 secondary 'normalize-space(concat(secondary/@sortas, secondary[not(@sortas)]))'>
  7. <!ENTITY scope 'count(ancestor::node()|$scope) = count(ancestor::node())'>
  8. <!ENTITY sep '" "'>
  9. ]>
  10. <!-- Version 0.9 - Manuel Canales Esparcia <macana@lfs-es.org> -->
  11. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  12. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  13. version="1.0">
  14. <!--Only one column to fit the table layout-->
  15. <xsl:param name="column.count.index" select="1"/>
  16. <!--Title-->
  17. <xsl:template match="index" mode="title.markup">
  18. <xsl:text>Index of packages and important installed files</xsl:text>
  19. </xsl:template>
  20. <!-- Divisions-->
  21. <xsl:template match="indexterm" mode="index-div">
  22. <xsl:param name="scope" select="."/>
  23. <xsl:variable name="key"
  24. select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  25. <xsl:variable name="divtitle" select="translate($key, &lowercase;, &uppercase;)"/>
  26. <xsl:if test="key('letter', $key)[&scope;]
  27. [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  28. <fo:block>
  29. <xsl:if test="contains(concat(&lowercase;, &uppercase;), $key)">
  30. <xsl:call-template name="indexdiv.title">
  31. <xsl:with-param name="titlecontent">
  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. </xsl:with-param>
  53. </xsl:call-template>
  54. </xsl:if>
  55. <fo:table table-layout="fixed" width="100%">
  56. <fo:table-column column-number="1" column-width="11em"/>
  57. <fo:table-column column-number="2" column-width="19em"/>
  58. <fo:table-column column-number="3"/>
  59. <fo:table-body>
  60. <xsl:apply-templates select="key('letter', $key)[&scope;]
  61. [count(.|key('primary', &primary;)[&scope;][1])=1]"
  62. mode="index-primary">
  63. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  64. <xsl:with-param name="scope" select="$scope"/>
  65. </xsl:apply-templates>
  66. </fo:table-body>
  67. </fo:table>
  68. </fo:block>
  69. </xsl:if>
  70. </xsl:template>
  71. <!-- Dropping the separator from here -->
  72. <xsl:template match="indexterm" mode="reference">
  73. <xsl:param name="scope" select="."/>
  74. <xsl:call-template name="reference">
  75. <xsl:with-param name="zones" select="normalize-space(@zone)"/>
  76. <xsl:with-param name="scope" select="$scope"/>
  77. </xsl:call-template>
  78. </xsl:template>
  79. <!-- Changing the output tags and re-addind the separator-->
  80. <xsl:template match="indexterm" mode="index-primary">
  81. <xsl:param name="scope" select="."/>
  82. <xsl:variable name="key" select="&primary;"/>
  83. <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
  84. <fo:table-row>
  85. <fo:table-cell>
  86. <fo:block>
  87. <xsl:value-of select="primary"/>
  88. <xsl:text>: </xsl:text>
  89. </fo:block>
  90. </fo:table-cell>
  91. <xsl:for-each select="$refs[not(see) and not(seealso)
  92. and not(secondary)]">
  93. <xsl:apply-templates select="." mode="reference">
  94. <xsl:with-param name="scope" select="$scope"/>
  95. </xsl:apply-templates>
  96. </xsl:for-each>
  97. </fo:table-row>
  98. <xsl:if test="$refs/secondary">
  99. <xsl:apply-templates select="$refs[secondary and count(.|key('secondary',
  100. concat($key, &sep;, &secondary;))[&scope;][1]) = 1]" mode="index-secondary">
  101. <xsl:with-param name="scope" select="$scope"/>
  102. <xsl:sort select="translate(&secondary;, &lowercase;, &uppercase;)"/>
  103. </xsl:apply-templates>
  104. </xsl:if>
  105. </xsl:template>
  106. <xsl:template match="indexterm" mode="index-secondary">
  107. <xsl:param name="scope" select="."/>
  108. <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
  109. <xsl:variable name="refs" select="key('secondary', $key)[&scope;]"/>
  110. <fo:table-row>
  111. <fo:table-cell>
  112. <fo:block start-indent="1pc">
  113. <xsl:value-of select="secondary"/>
  114. <xsl:text>: </xsl:text>
  115. </fo:block>
  116. </fo:table-cell>
  117. <xsl:for-each select="$refs[not(see) and not(seealso) and not(tertiary)]">
  118. <xsl:apply-templates select="." mode="reference">
  119. <xsl:with-param name="scope" select="$scope"/>
  120. </xsl:apply-templates>
  121. </xsl:for-each>
  122. </fo:table-row>
  123. </xsl:template>
  124. <!-- Targets titles and bookmarks-->
  125. <xsl:template name="reference">
  126. <xsl:param name="scope" select="."/>
  127. <xsl:param name="zones"/>
  128. <xsl:choose>
  129. <xsl:when test="contains($zones, ' ')">
  130. <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
  131. <xsl:variable name="zone2" select="substring-after($zones, ' ')"/>
  132. <xsl:variable name="target" select="key('id', $zone)[&scope;]"/>
  133. <xsl:variable name="target2" select="key('id', $zone2)[&scope;]"/>
  134. <xsl:variable name="id">
  135. <xsl:call-template name="object.id">
  136. <xsl:with-param name="object" select="$target[1]"/>
  137. </xsl:call-template>
  138. </xsl:variable>
  139. <xsl:variable name="id2">
  140. <xsl:call-template name="object.id">
  141. <xsl:with-param name="object" select="$target2[1]"/>
  142. </xsl:call-template>
  143. </xsl:variable>
  144. <fo:table-cell>
  145. <fo:block>
  146. <fo:basic-link internal-destination="{$id}">
  147. <xsl:value-of select="$target/title"/>
  148. <xsl:apply-templates select="$target" mode="page.citation">
  149. <xsl:with-param name="id" select="$id"/>
  150. </xsl:apply-templates>
  151. </fo:basic-link>
  152. </fo:block>
  153. </fo:table-cell>
  154. <fo:table-cell>
  155. <fo:block>
  156. <fo:basic-link internal-destination="{$id2}">
  157. <xsl:text>description</xsl:text>
  158. <xsl:apply-templates select="$target2" mode="page.citation">
  159. <xsl:with-param name="id" select="$id2"/>
  160. </xsl:apply-templates>
  161. </fo:basic-link>
  162. </fo:block>
  163. </fo:table-cell>
  164. </xsl:when>
  165. <xsl:otherwise>
  166. <xsl:variable name="zone" select="$zones"/>
  167. <xsl:variable name="target" select="key('id', $zone)[&scope;]"/>
  168. <xsl:variable name="id">
  169. <xsl:call-template name="object.id">
  170. <xsl:with-param name="object" select="$target[1]"/>
  171. </xsl:call-template>
  172. </xsl:variable>
  173. <fo:table-cell>
  174. <fo:block>
  175. <fo:basic-link internal-destination="{$id}">
  176. <xsl:value-of select="$target/title"/>
  177. <xsl:apply-templates select="$target" mode="page.citation">
  178. <xsl:with-param name="id" select="$id"/>
  179. </xsl:apply-templates>
  180. </fo:basic-link>
  181. </fo:block>
  182. </fo:table-cell>
  183. </xsl:otherwise>
  184. </xsl:choose>
  185. </xsl:template>
  186. </xsl:stylesheet>