lfs-index.xsl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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:fo="http://www.w3.org/1999/XSL/Format"
  10. version="1.0">
  11. <!--Title-->
  12. <xsl:template match="index" mode="title.markup">
  13. <xsl:param name="allow-anchors" select="0"/>
  14. <xsl:call-template name="gentext">
  15. <xsl:with-param name="key">Index</xsl:with-param>
  16. </xsl:call-template>
  17. </xsl:template>
  18. <!-- Divisions-->
  19. <xsl:template match="indexterm" mode="index-div">
  20. <xsl:param name="scope" select="."/>
  21. <xsl:variable name="key"
  22. select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  23. <xsl:variable name="divtitle" select="translate($key, &lowercase;, &uppercase;)"/>
  24. <xsl:if test="key('letter', $key)[&scope;]
  25. [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  26. <fo:block>
  27. <xsl:if test="contains(concat(&lowercase;, &uppercase;), $key)">
  28. <xsl:call-template name="indexdiv.title">
  29. <xsl:with-param name="titlecontent">
  30. <xsl:choose>
  31. <xsl:when test="$divtitle = 'A'">
  32. <xsl:call-template name="gentext">
  33. <xsl:with-param name="key">Packages</xsl:with-param>
  34. </xsl:call-template>
  35. </xsl:when>
  36. <xsl:when test="$divtitle = 'B'">
  37. <xsl:call-template name="gentext">
  38. <xsl:with-param name="key">Programs</xsl:with-param>
  39. </xsl:call-template>
  40. </xsl:when>
  41. <xsl:when test="$divtitle = 'C'">
  42. <xsl:call-template name="gentext">
  43. <xsl:with-param name="key">Libraries</xsl:with-param>
  44. </xsl:call-template>
  45. </xsl:when>
  46. <xsl:when test="$divtitle = 'D'">
  47. <xsl:call-template name="gentext">
  48. <xsl:with-param name="key">Scripts</xsl:with-param>
  49. </xsl:call-template>
  50. </xsl:when>
  51. <xsl:when test="$divtitle = 'E'">
  52. <xsl:call-template name="gentext">
  53. <xsl:with-param name="key">Others</xsl:with-param>
  54. </xsl:call-template>
  55. </xsl:when>
  56. <xsl:otherwise>
  57. <xsl:value-of select="$divtitle"/>
  58. </xsl:otherwise>
  59. </xsl:choose>
  60. </xsl:with-param>
  61. </xsl:call-template>
  62. </xsl:if>
  63. <fo:block>
  64. <xsl:apply-templates select="key('letter', $key)[&scope;]
  65. [count(.|key('primary', &primary;)[&scope;][1])=1]"
  66. mode="index-primary">
  67. <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
  68. <xsl:with-param name="scope" select="$scope"/>
  69. </xsl:apply-templates>
  70. </fo:block>
  71. </fo:block>
  72. </xsl:if>
  73. </xsl:template>
  74. <!-- The separator -->
  75. <xsl:template match="indexterm" mode="reference">
  76. <xsl:param name="scope" select="."/>
  77. <xsl:text>: </xsl:text>
  78. <xsl:call-template name="reference">
  79. <xsl:with-param name="zones" select="normalize-space(@zone)"/>
  80. <xsl:with-param name="scope" select="$scope"/>
  81. </xsl:call-template>
  82. </xsl:template>
  83. <!--Bookmarks-->
  84. <xsl:template name="reference">
  85. <xsl:param name="scope" select="."/>
  86. <xsl:param name="zones"/>
  87. <xsl:choose>
  88. <xsl:when test="contains($zones, ' ')">
  89. <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
  90. <xsl:variable name="zone2" select="substring-after($zones, ' ')"/>
  91. <xsl:variable name="target" select="key('id', $zone)[&scope;]"/>
  92. <xsl:variable name="target2" select="key('id', $zone2)[&scope;]"/>
  93. <xsl:variable name="id">
  94. <xsl:call-template name="object.id">
  95. <xsl:with-param name="object" select="$target[1]"/>
  96. </xsl:call-template>
  97. </xsl:variable>
  98. <xsl:variable name="id2">
  99. <xsl:call-template name="object.id">
  100. <xsl:with-param name="object" select="$target2[1]"/>
  101. </xsl:call-template>
  102. </xsl:variable>
  103. <fo:basic-link internal-destination="{$id}">
  104. <xsl:apply-templates select="$target" mode="page.citation">
  105. <xsl:with-param name="id" select="$id"/>
  106. </xsl:apply-templates>
  107. </fo:basic-link>
  108. <xsl:text> , </xsl:text>
  109. <fo:basic-link internal-destination="{$id2}">
  110. <xsl:apply-templates select="$target2" mode="page.citation">
  111. <xsl:with-param name="id" select="$id2"/>
  112. </xsl:apply-templates>
  113. </fo:basic-link>
  114. </xsl:when>
  115. <xsl:otherwise>
  116. <xsl:variable name="zone" select="$zones"/>
  117. <xsl:variable name="target" select="key('id', $zone)[&scope;]"/>
  118. <xsl:variable name="id">
  119. <xsl:call-template name="object.id">
  120. <xsl:with-param name="object" select="$target[1]"/>
  121. </xsl:call-template>
  122. </xsl:variable>
  123. <fo:basic-link internal-destination="{$id}">
  124. <xsl:apply-templates select="$target" mode="page.citation">
  125. <xsl:with-param name="id" select="$id"/>
  126. </xsl:apply-templates>
  127. </fo:basic-link>
  128. </xsl:otherwise>
  129. </xsl:choose>
  130. </xsl:template>
  131. <!-- Page number in Index-->
  132. <xsl:template match="*" mode="page.citation">
  133. <xsl:param name="id" select="'???'"/>
  134. <fo:inline keep-together.within-line="always">
  135. <!--<xsl:text>[p</xsl:text>-->
  136. <fo:page-number-citation ref-id="{$id}"/>
  137. <!--<xsl:text>]</xsl:text>-->
  138. </fo:inline>
  139. </xsl:template>
  140. </xsl:stylesheet>