autoidx-kosek.xsl 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?xml version="1.0"?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY primary 'normalize-space(concat(primary/@sortas, primary[not(@sortas) or @sortas = ""]))'>
  4. <!ENTITY secondary 'normalize-space(concat(secondary/@sortas, secondary[not(@sortas) or @sortas = ""]))'>
  5. <!ENTITY tertiary 'normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas) or @sortas = ""]))'>
  6. <!ENTITY sep '" "'>
  7. <!-- Documents using the kimber index method must have a lang attribute -->
  8. <!-- Only one of these should be present in the entity -->
  9. <!ENTITY scope 'count(ancestor::node()|$scope) = count(ancestor::node())
  10. and ($role = @role or $type = @type or
  11. (string-length($role) = 0 and string-length($type) = 0))'>
  12. ]>
  13. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  14. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  15. xmlns:rx="http://www.renderx.com/XSL/Extensions"
  16. xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
  17. xmlns:i="urn:cz-kosek:functions:index"
  18. xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
  19. xmlns:func="http://exslt.org/functions"
  20. xmlns:exslt="http://exslt.org/common"
  21. extension-element-prefixes="func exslt"
  22. exclude-result-prefixes="func exslt i l"
  23. version="1.0">
  24. <!-- ********************************************************************
  25. $Id$
  26. ********************************************************************
  27. This file is part of the DocBook XSL Stylesheet distribution.
  28. See ../README or http://docbook.sf.net/ for copyright
  29. copyright and other information.
  30. ******************************************************************** -->
  31. <!-- ==================================================================== -->
  32. <!-- The "kosek" method contributed by Jirka Kosek. -->
  33. <xsl:include href="../common/autoidx-kosek.xsl"/>
  34. <xsl:template name="generate-kosek-index">
  35. <xsl:param name="scope" select="NOTANODE"/>
  36. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  37. <xsl:if test="contains($vendor, 'libxslt')">
  38. <xsl:message terminate="yes">
  39. <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
  40. <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
  41. </xsl:message>
  42. </xsl:if>
  43. <xsl:if test="contains($vendor, 'Saxonica')">
  44. <xsl:message terminate="yes">
  45. <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
  46. <xsl:text>work with the Saxon 8 XSLT processor.</xsl:text>
  47. </xsl:message>
  48. </xsl:if>
  49. <xsl:if test="not(function-available('exslt:node-set') or
  50. function-available('exslt:nodeSet'))">
  51. <xsl:message terminate="yes">
  52. <xsl:text>ERROR: the 'kosek' index method requires the </xsl:text>
  53. <xsl:text>exslt:node-set() function. Use a processor that </xsl:text>
  54. <xsl:text>has it, or use a different index method.</xsl:text>
  55. </xsl:message>
  56. </xsl:if>
  57. <xsl:if test="not(function-available('i:group-index'))">
  58. <xsl:message terminate="yes">
  59. <xsl:text>ERROR: the 'kosek' index method requires the&#xA;</xsl:text>
  60. <xsl:text>index extension functions be imported:&#xA;</xsl:text>
  61. <xsl:text> xsl:import href="common/autoidx-kosek.xsl"</xsl:text>
  62. </xsl:message>
  63. </xsl:if>
  64. <xsl:variable name="role">
  65. <xsl:if test="$index.on.role != 0">
  66. <xsl:value-of select="@role"/>
  67. </xsl:if>
  68. </xsl:variable>
  69. <xsl:variable name="type">
  70. <xsl:if test="$index.on.type != 0">
  71. <xsl:value-of select="@type"/>
  72. </xsl:if>
  73. </xsl:variable>
  74. <xsl:variable name="terms"
  75. select="//indexterm[count(.|key('group-code',
  76. i:group-index(&primary;))
  77. [&scope;][1]) = 1
  78. and not(@class = 'endofrange')]"/>
  79. <fo:block>
  80. <xsl:apply-templates select="$terms" mode="index-div-kosek">
  81. <xsl:with-param name="scope" select="$scope"/>
  82. <xsl:with-param name="role" select="$role"/>
  83. <xsl:with-param name="type" select="$type"/>
  84. <xsl:sort select="i:group-index(&primary;)" data-type="number"/>
  85. </xsl:apply-templates>
  86. </fo:block>
  87. </xsl:template>
  88. <xsl:template match="indexterm" mode="index-div-kosek">
  89. <xsl:param name="scope" select="."/>
  90. <xsl:param name="role" select="''"/>
  91. <xsl:param name="type" select="''"/>
  92. <xsl:variable name="key"
  93. select="i:group-index(&primary;)"/>
  94. <xsl:variable name="lang">
  95. <xsl:call-template name="l10n.language"/>
  96. </xsl:variable>
  97. <xsl:if test="key('group-code', $key)[&scope;]
  98. [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  99. <fo:block>
  100. <xsl:call-template name="indexdiv.title">
  101. <xsl:with-param name="titlecontent">
  102. <xsl:choose>
  103. <xsl:when test="$key = 0">
  104. <xsl:call-template name="gentext">
  105. <xsl:with-param name="key" select="'index symbols'"/>
  106. </xsl:call-template>
  107. </xsl:when>
  108. <xsl:otherwise>
  109. <xsl:value-of select="i:group-letter($key)"/>
  110. </xsl:otherwise>
  111. </xsl:choose>
  112. </xsl:with-param>
  113. </xsl:call-template>
  114. <fo:block>
  115. <xsl:apply-templates select="key('group-code', $key)[&scope;]
  116. [count(.|key('primary', &primary;)
  117. [&scope;][1])=1]"
  118. mode="index-primary">
  119. <xsl:sort select="&primary;" lang="{$lang}"/>
  120. <xsl:with-param name="scope" select="$scope"/>
  121. <xsl:with-param name="role" select="$role"/>
  122. <xsl:with-param name="type" select="$type"/>
  123. </xsl:apply-templates>
  124. </fo:block>
  125. </fo:block>
  126. </xsl:if>
  127. </xsl:template>
  128. </xsl:stylesheet>