index_fop.xsl 4.2 KB

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