abbrev-domain.xsl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- This file is part of the DITA Open Toolkit project.
  3. See the accompanying license.txt file for applicable licenses. -->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  5. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  6. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  7. xmlns:opentopic="http://www.idiominc.com/opentopic"
  8. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  9. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
  10. version="2.0"
  11. exclude-result-prefixes="xs opentopic dita-ot ditamsg">
  12. <xsl:param name="first-use-scope" select="'document'"/>
  13. <xsl:key name="abbreviated-form-keyref"
  14. match="*[contains(@class, ' abbrev-d/abbreviated-form ')]
  15. [empty(ancestor::opentopic:map) and empty(ancestor::*[contains(@class, ' topic/title ')])]
  16. [@keyref]"
  17. use="@keyref"/>
  18. <xsl:template match="*[contains(@class,' abbrev-d/abbreviated-form ')]" name="topic.abbreviated-form">
  19. <xsl:variable name="keys" select="@keyref"/>
  20. <xsl:variable name="target" select="key('id', substring(@href, 2))"/>
  21. <xsl:choose>
  22. <xsl:when test="$keys and $target/self::*[contains(@class,' glossentry/glossentry ')]">
  23. <xsl:call-template name="topic.term">
  24. <xsl:with-param name="contents">
  25. <xsl:variable name="use-abbreviated-form" as="xs:boolean">
  26. <xsl:apply-templates select="." mode="use-abbreviated-form"/>
  27. </xsl:variable>
  28. <xsl:choose>
  29. <xsl:when test="$use-abbreviated-form">
  30. <xsl:apply-templates select="$target" mode="getMatchingAcronym"/>
  31. </xsl:when>
  32. <xsl:otherwise>
  33. <xsl:apply-templates select="$target" mode="getMatchingSurfaceForm"/>
  34. </xsl:otherwise>
  35. </xsl:choose>
  36. </xsl:with-param>
  37. </xsl:call-template>
  38. </xsl:when>
  39. <xsl:otherwise>
  40. <xsl:apply-templates select="." mode="ditamsg:no-glossentry-for-abbreviated-form">
  41. <xsl:with-param name="keys" select="$keys"/>
  42. </xsl:apply-templates>
  43. </xsl:otherwise>
  44. </xsl:choose>
  45. </xsl:template>
  46. <!-- Should abbreviated form of glossary entry be used -->
  47. <xsl:template match="*" mode="use-abbreviated-form" as="xs:boolean">
  48. <xsl:variable name="first-use-scope-root" as="element()">
  49. <xsl:call-template name="get-first-use-scope-root"/>
  50. </xsl:variable>
  51. <xsl:sequence select="not(generate-id(.) = generate-id(key('abbreviated-form-keyref', @keyref, $first-use-scope-root)[1]))"/>
  52. </xsl:template>
  53. <xsl:template match="*[contains(@class,' topic/copyright ')]//*" mode="use-abbreviated-form" as="xs:boolean">
  54. <xsl:sequence select="false()"/>
  55. </xsl:template>
  56. <xsl:template match="*[contains(@class,' topic/title ')]//*" mode="use-abbreviated-form" as="xs:boolean">
  57. <xsl:sequence select="true()"/>
  58. </xsl:template>
  59. <!-- Get element to use as root when -->
  60. <xsl:template name="get-first-use-scope-root" as="element()">
  61. <xsl:choose>
  62. <xsl:when test="$first-use-scope = 'topic'">
  63. <xsl:sequence select="ancestor::*[contains(@class, ' topic/topic ')][1]"/>
  64. </xsl:when>
  65. <xsl:when test="$first-use-scope = 'chapter'">
  66. <xsl:sequence select="ancestor::*[contains(@class, ' topic/topic ')][position() = last()]"/>
  67. </xsl:when>
  68. <xsl:otherwise>
  69. <xsl:sequence select="/*"/>
  70. </xsl:otherwise>
  71. </xsl:choose>
  72. </xsl:template>
  73. <xsl:template match="*" mode="getMatchingSurfaceForm">
  74. <xsl:variable name="glossSurfaceForm" select="*[contains(@class, ' glossentry/glossBody ')]/*[contains(@class, ' glossentry/glossSurfaceForm ')]"/>
  75. <xsl:choose>
  76. <xsl:when test="$glossSurfaceForm">
  77. <xsl:apply-templates select="$glossSurfaceForm/node()"/>
  78. </xsl:when>
  79. <xsl:otherwise>
  80. <xsl:apply-templates select="*[contains(@class, ' glossentry/glossterm ')]/node()"/>
  81. </xsl:otherwise>
  82. </xsl:choose>
  83. </xsl:template>
  84. <xsl:template match="*" mode="getMatchingAcronym">
  85. <xsl:variable name="glossAcronym" select="*[contains(@class, ' glossentry/glossBody ')]/*[contains(@class, ' glossentry/glossAlt ')]/*[contains(@class, ' glossentry/glossAcronym ')]"/>
  86. <xsl:choose>
  87. <xsl:when test="$glossAcronym">
  88. <xsl:apply-templates select="$glossAcronym[1]/node()"/>
  89. </xsl:when>
  90. <xsl:otherwise>
  91. <xsl:apply-templates select="*[contains(@class, ' glossentry/glossterm ')]/node()"/>
  92. </xsl:otherwise>
  93. </xsl:choose>
  94. </xsl:template>
  95. <xsl:template match="*" mode="ditamsg:no-glossentry-for-abbreviated-form">
  96. <xsl:param name="keys"/>
  97. <xsl:call-template name="output-message">
  98. <xsl:with-param name="id" select="'DOTX060W'"/>
  99. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$keys"/></xsl:with-param>
  100. </xsl:call-template>
  101. </xsl:template>
  102. </xsl:stylesheet>