abbrev-domain.xsl 5.0 KB

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