lfs-index.xsl 5.3 KB

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