index_fop.xsl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. Copyright 2011 Jarno Elovirta
  5. See the accompanying LICENSE file for applicable license.
  6. -->
  7. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  9. xmlns:opentopic-index="http://www.idiominc.com/opentopic/index"
  10. xmlns:opentopic-func="http://www.idiominc.com/opentopic/exsl/function"
  11. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  12. version="2.0"
  13. exclude-result-prefixes="opentopic-index opentopic-func xs">
  14. <xsl:variable name="index.continued-enabled" select="false()"/>
  15. <xsl:variable name="UNIQUE_INFIX" select="'_unique_'" as="xs:string"/>
  16. <xsl:function name="opentopic-func:get-unique-refid-value" as="xs:string">
  17. <xsl:param name="el" as="element(opentopic-index:refID)"/>
  18. <xsl:sequence
  19. select="concat($el/@value, $UNIQUE_INFIX, generate-id($el))"/>
  20. </xsl:function>
  21. <xsl:key name="refid-by-value" use="@value" match="opentopic-index:refID"/>
  22. <xsl:key name="refid-by-end-range-value"
  23. use="ancestor-or-self::opentopic-index:index.entry[@end-range]/@value"
  24. match="opentopic-index:refID[empty(ancestor::opentopic-index:index.groups)]"/>
  25. <xsl:template match="opentopic-index:index.entry[opentopic-index:refID/@value]">
  26. <!--Insert simple index entry marker-->
  27. <xsl:apply-templates
  28. select="opentopic-index:refID[last()]" mode="make-wrapper"/>
  29. <xsl:apply-templates/>
  30. </xsl:template>
  31. <xsl:template match="opentopic-index:refID" mode="make-wrapper">
  32. <fo:wrapper id="{opentopic-func:get-unique-refid-value(.)}"/>
  33. </xsl:template>
  34. <xsl:template match="opentopic-index:index.entry" mode="make-index-ref">
  35. <xsl:param name="idxs" as="element(opentopic-index:refID)*"/>
  36. <xsl:param name="inner-text" as="element(opentopic-index:formatted-value)*"/>
  37. <xsl:param name="no-page"/>
  38. <fo:block id="{generate-id()}" xsl:use-attribute-sets="index.term">
  39. <xsl:if test="empty(preceding-sibling::opentopic-index:index.entry)">
  40. <xsl:attribute name="keep-with-previous">always</xsl:attribute>
  41. </xsl:if>
  42. <fo:inline>
  43. <xsl:apply-templates select="$inner-text/node()"/>
  44. </fo:inline>
  45. <xsl:if test="not($no-page) and exists($idxs)">
  46. <xsl:sequence select="$index.separator"/>
  47. <xsl:variable name="links" as="element()*">
  48. <xsl:for-each select="$idxs">
  49. <xsl:apply-templates mode="make-index-links"
  50. select="key('refid-by-value', @value)
  51. [empty(ancestor-or-self::opentopic-index:index.entry[@end-range])]
  52. [empty(ancestor::opentopic-index:index.groups)]
  53. [empty(ancestor::*[@no-page eq 'true'])]
  54. [ancestor::*[contains(@class,' topic/topic ')]]"/>
  55. </xsl:for-each>
  56. </xsl:variable>
  57. <xsl:for-each select="$links">
  58. <xsl:if test="not(position() eq 1)">
  59. <xsl:text>, </xsl:text>
  60. </xsl:if>
  61. <xsl:sequence select="."/>
  62. </xsl:for-each>
  63. </xsl:if>
  64. <xsl:if test="@no-page eq 'true'">
  65. <xsl:apply-templates select="opentopic-index:see-childs" mode="index-postprocess"/>
  66. </xsl:if>
  67. <xsl:if test="empty(opentopic-index:index.entry)">
  68. <xsl:apply-templates select="opentopic-index:see-also-childs" mode="index-postprocess"/>
  69. </xsl:if>
  70. </fo:block>
  71. </xsl:template>
  72. <xsl:template match="opentopic-index:refID" mode="make-index-links">
  73. <xsl:variable name="value" as="xs:string"
  74. select="opentopic-func:get-unique-refid-value(.)"/>
  75. <fo:basic-link internal-destination="{$value}" xsl:use-attribute-sets="common.link">
  76. <fo:page-number-citation ref-id="{$value}"/>
  77. <xsl:variable name="start-range-value" as="attribute(value)?"
  78. select="ancestor-or-self::opentopic-index:index.entry[@start-range]/@value"/>
  79. <xsl:apply-templates mode="make-page-number-citation"
  80. select="key('refid-by-end-range-value', $start-range-value)"/>
  81. </fo:basic-link>
  82. </xsl:template>
  83. <xsl:template match="opentopic-index:refID" mode="make-page-number-citation">
  84. <xsl:text>-</xsl:text>
  85. <fo:page-number-citation
  86. ref-id="{opentopic-func:get-unique-refid-value(.)}"/>
  87. </xsl:template>
  88. </xsl:stylesheet>