ut-d.xsl 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
  4. exclude-result-prefixes="ditamsg">
  5. <xsl:template match="*[contains(@class,' ut-d/imagemap ')]" name="topic.ut-d.imagemap">
  6. <div>
  7. <xsl:call-template name="commonattributes"/>
  8. <xsl:call-template name="setidaname"/>
  9. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  10. <!-- the image -->
  11. <image usemap="#{generate-id()}">
  12. <!-- Border attribute defaults to 0 -->
  13. <xsl:apply-templates select="." mode="imagemap-border-attribute"/>
  14. <!-- Process the 'normal' image attributes, using this special mode -->
  15. <xsl:apply-templates select="*[contains(@class,' topic/image ')]" mode="imagemap-image"/>
  16. </image>
  17. <map name="{generate-id(.)}" id="{generate-id(.)}">
  18. <xsl:for-each select="*[contains(@class,' ut-d/area ')]">
  19. <area>
  20. <!-- if no xref/@href - error -->
  21. <xsl:choose>
  22. <xsl:when test="*[contains(@class,' topic/xref ')]/@href">
  23. <!-- special call to have the XREF/@HREF processor do the work -->
  24. <xsl:apply-templates select="*[contains(@class, ' topic/xref ')]" mode="imagemap-xref"/>
  25. </xsl:when>
  26. <xsl:otherwise>
  27. <xsl:apply-templates select="." mode="ditamsg:area-element-without-href-target"/>
  28. </xsl:otherwise>
  29. </xsl:choose>
  30. <!-- create ALT text from XREF content-->
  31. <!-- if no XREF content, use @HREF, & put out a warning -->
  32. <xsl:choose>
  33. <xsl:when test="*[contains(@class, ' topic/xref ')]">
  34. <xsl:variable name="alttext">
  35. <xsl:apply-templates select="*[contains(@class, ' topic/xref ')]/node()[not(contains(@class, ' topic/desc '))]" mode="text-only"/>
  36. </xsl:variable>
  37. <xsl:attribute name="alt">
  38. <xsl:value-of select="normalize-space($alttext)"/>
  39. </xsl:attribute>
  40. <xsl:attribute name="title">
  41. <xsl:value-of select="normalize-space($alttext)"/>
  42. </xsl:attribute>
  43. </xsl:when>
  44. <xsl:otherwise>
  45. <xsl:apply-templates select="." mode="ditamsg:area-element-without-linktext"/>
  46. </xsl:otherwise>
  47. </xsl:choose>
  48. <!-- if not valid shape (blank, rect, circle, poly); Warning, pass thru the value -->
  49. <xsl:variable name="shapeval">
  50. <xsl:value-of select="*[contains(@class,' ut-d/shape ')]"/>
  51. </xsl:variable>
  52. <xsl:attribute name="shape">
  53. <xsl:value-of select="$shapeval"/>
  54. </xsl:attribute>
  55. <xsl:variable name="shapetest">
  56. <xsl:value-of select="concat('-',$shapeval,'-')"/>
  57. </xsl:variable>
  58. <xsl:choose>
  59. <xsl:when test="contains('--rect-circle-poly-default-',$shapetest)"/>
  60. <xsl:otherwise>
  61. <xsl:apply-templates select="." mode="ditamsg:area-element-unknown-shape">
  62. <xsl:with-param name="shapeval" select="$shapeval"/>
  63. </xsl:apply-templates>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. <!-- if no coords & shape<>'default'; Warning, pass thru the value -->
  67. <xsl:variable name="coordval">
  68. <xsl:value-of select="*[contains(@class,' ut-d/coords ')]"/>
  69. </xsl:variable>
  70. <xsl:choose>
  71. <xsl:when test="string-length($coordval)>0 and not($shapeval='default')">
  72. <xsl:attribute name="coords">
  73. <xsl:value-of select="$coordval"/>
  74. </xsl:attribute>
  75. </xsl:when>
  76. <xsl:otherwise>
  77. <xsl:apply-templates select="." mode="ditamsg:area-element-missing-coords"/>
  78. </xsl:otherwise>
  79. </xsl:choose>
  80. </area>
  81. </xsl:for-each>
  82. </map>
  83. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  84. </div>
  85. </xsl:template>
  86. <!-- Set the border attribute on an imagemap; default is to always use border="0" -->
  87. <xsl:template match="*[contains(@class,' ut-d/imagemap ')]" mode="imagemap-border-attribute">
  88. <xsl:attribute name="border">0</xsl:attribute>
  89. </xsl:template>
  90. <!-- In the context of IMAGE - call these attribute processors -->
  91. <xsl:template match="*[contains(@class, ' topic/image ')]" mode="imagemap-image">
  92. <xsl:call-template name="commonattributes"/>
  93. <xsl:call-template name="setid"/>
  94. <xsl:apply-templates select="@href|@height|@width"/>
  95. <xsl:choose>
  96. <xsl:when test="*[contains(@class, ' topic/longdescref ')]">
  97. <xsl:apply-templates select="*[contains(@class, ' topic/longdescref ')]"/>
  98. </xsl:when>
  99. <xsl:otherwise>
  100. <xsl:apply-templates select="@longdescref"/>
  101. </xsl:otherwise>
  102. </xsl:choose>
  103. <xsl:choose>
  104. <xsl:when test="*[contains(@class,' topic/alt ')]">
  105. <xsl:attribute name="alt">
  106. <xsl:apply-templates select="*[contains(@class,' topic/alt ')]" mode="text-only"/>
  107. </xsl:attribute>
  108. </xsl:when>
  109. <xsl:when test="@alt">
  110. <xsl:attribute name="alt">
  111. <xsl:value-of select="@alt"/>
  112. </xsl:attribute>
  113. </xsl:when>
  114. </xsl:choose>
  115. </xsl:template>
  116. <!-- In the context of XREF - call it's HREF processor -->
  117. <xsl:template match="*[contains(@class, ' topic/xref ')]" mode="imagemap-xref">
  118. <xsl:attribute name="href">
  119. <xsl:call-template name="href"/>
  120. </xsl:attribute>
  121. <xsl:if test="@scope='external' or @type='external' or ((@format='PDF' or @format='pdf') and not(@scope='local'))">
  122. <xsl:attribute name="target">_blank</xsl:attribute>
  123. </xsl:if>
  124. </xsl:template>
  125. <xsl:template match="*" mode="ditamsg:area-element-without-href-target">
  126. <xsl:call-template name="output-message">
  127. <xsl:with-param name="id">DOTX044E</xsl:with-param>
  128. </xsl:call-template>
  129. </xsl:template>
  130. <xsl:template match="*" mode="ditamsg:area-element-without-linktext">
  131. <xsl:call-template name="output-message">
  132. <xsl:with-param name="id">DOTX045W</xsl:with-param>
  133. </xsl:call-template>
  134. </xsl:template>
  135. <xsl:template match="*" mode="ditamsg:area-element-unknown-shape">
  136. <xsl:param name="shapeval" select="*[contains(@class,' ut-d/shape ')]/text()"/>
  137. <xsl:call-template name="output-message">
  138. <xsl:with-param name="id">DOTX046W</xsl:with-param>
  139. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$shapeval"/></xsl:with-param>
  140. </xsl:call-template>
  141. </xsl:template>
  142. <xsl:template match="*" mode="ditamsg:area-element-missing-coords">
  143. <xsl:call-template name="output-message">
  144. <xsl:with-param name="id">DOTX047W</xsl:with-param>
  145. </xsl:call-template>
  146. </xsl:template>
  147. </xsl:stylesheet>