ut-d.xsl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. Copyright 2004, 2005 IBM Corporation
  5. See the accompanying LICENSE file for applicable license.
  6. -->
  7. <xsl:stylesheet version="2.0"
  8. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  9. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
  10. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  11. exclude-result-prefixes="ditamsg xs">
  12. <!-- == User Technologies UNIQUE SUBSTRUCTURES == -->
  13. <!-- imagemap -->
  14. <xsl:template match="*[contains(@class,' ut-d/imagemap ')]" name="topic.ut-d.imagemap">
  15. <div>
  16. <xsl:call-template name="commonattributes"/>
  17. <xsl:call-template name="setidaname"/>
  18. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  19. <!-- the image -->
  20. <img usemap="#{generate-id()}">
  21. <!-- Border attribute defaults to 0 -->
  22. <xsl:apply-templates select="." mode="imagemap-border-attribute"/>
  23. <!-- Process the 'normal' image attributes, using this special mode -->
  24. <xsl:apply-templates select="*[contains(@class,' topic/image ')]" mode="imagemap-image"/>
  25. </img>
  26. <xsl:value-of select="$newline"/>
  27. <map name="{generate-id(.)}" id="{generate-id(.)}">
  28. <xsl:for-each select="*[contains(@class,' ut-d/area ')]">
  29. <xsl:value-of select="$newline"/>
  30. <area>
  31. <!-- if no xref/@href - error -->
  32. <xsl:choose>
  33. <xsl:when test="*[contains(@class,' topic/xref ')]/@href">
  34. <!-- special call to have the XREF/@HREF processor do the work -->
  35. <xsl:apply-templates select="*[contains(@class, ' topic/xref ')]" mode="imagemap-xref"/>
  36. </xsl:when>
  37. <xsl:otherwise>
  38. <xsl:apply-templates select="." mode="ditamsg:area-element-without-href-target"/>
  39. </xsl:otherwise>
  40. </xsl:choose>
  41. <!-- create ALT text from XREF content-->
  42. <!-- if no XREF content, use @HREF, & put out a warning -->
  43. <xsl:choose>
  44. <xsl:when test="*[contains(@class, ' topic/xref ')]">
  45. <xsl:variable name="alttext"><xsl:apply-templates select="*[contains(@class, ' topic/xref ')]/node()[not(contains(@class, ' topic/desc '))]" mode="text-only"/></xsl:variable>
  46. <xsl:attribute name="alt"><xsl:value-of select="normalize-space($alttext)"/></xsl:attribute>
  47. <xsl:attribute name="title"><xsl:value-of select="normalize-space($alttext)"/></xsl:attribute>
  48. </xsl:when>
  49. <xsl:otherwise>
  50. <xsl:apply-templates select="." mode="ditamsg:area-element-without-linktext"/>
  51. </xsl:otherwise>
  52. </xsl:choose>
  53. <!-- if not valid shape (blank, rect, circle, poly); Warning, pass thru the value -->
  54. <xsl:variable name="shapeval"><xsl:value-of select="*[contains(@class,' ut-d/shape ')]"/></xsl:variable>
  55. <xsl:attribute name="shape">
  56. <xsl:value-of select="$shapeval"/>
  57. </xsl:attribute>
  58. <xsl:variable name="shapetest" select="concat('-',$shapeval,'-')" as="xs:string"/>
  59. <xsl:choose>
  60. <xsl:when test="contains('--rect-circle-poly-default-',$shapetest)"/>
  61. <xsl:otherwise>
  62. <xsl:apply-templates select="." mode="ditamsg:area-element-unknown-shape">
  63. <xsl:with-param name="shapeval" select="$shapeval"/>
  64. </xsl:apply-templates>
  65. </xsl:otherwise>
  66. </xsl:choose>
  67. <!-- if no coords & shape<>'default'; Warning, pass thru the value -->
  68. <xsl:variable name="coordval"><xsl:value-of select="*[contains(@class,' ut-d/coords ')]"/></xsl:variable>
  69. <xsl:choose>
  70. <xsl:when test="string-length($coordval)>0 and not($shapeval='default')">
  71. <xsl:attribute name="coords">
  72. <xsl:value-of select="$coordval"/>
  73. </xsl:attribute>
  74. </xsl:when>
  75. <xsl:otherwise>
  76. <xsl:apply-templates select="." mode="ditamsg:area-element-missing-coords"/>
  77. </xsl:otherwise>
  78. </xsl:choose>
  79. </area>
  80. </xsl:for-each>
  81. <xsl:value-of select="$newline"/>
  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"><xsl:apply-templates select="*[contains(@class,' topic/alt ')]" mode="text-only"/></xsl:attribute>
  106. </xsl:when>
  107. <xsl:when test="@alt">
  108. <xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
  109. </xsl:when>
  110. </xsl:choose>
  111. </xsl:template>
  112. <!-- In the context of XREF - call it's HREF processor -->
  113. <xsl:template match="*[contains(@class, ' topic/xref ')]" mode="imagemap-xref">
  114. <xsl:attribute name="href"><xsl:call-template name="href"/></xsl:attribute>
  115. <xsl:if test="@scope='external' or @type='external' or ((@format='PDF' or @format='pdf') and not(@scope='local'))">
  116. <xsl:attribute name="target">_blank</xsl:attribute>
  117. </xsl:if>
  118. </xsl:template>
  119. <xsl:template match="*" mode="ditamsg:area-element-without-href-target">
  120. <xsl:call-template name="output-message">
  121. <xsl:with-param name="id" select="'DOTX044E'"/>
  122. </xsl:call-template>
  123. </xsl:template>
  124. <xsl:template match="*" mode="ditamsg:area-element-without-linktext">
  125. <xsl:call-template name="output-message">
  126. <xsl:with-param name="id" select="'DOTX045W'"/>
  127. </xsl:call-template>
  128. </xsl:template>
  129. <xsl:template match="*" mode="ditamsg:area-element-unknown-shape">
  130. <xsl:param name="shapeval" select="*[contains(@class,' ut-d/shape ')]/text()"/>
  131. <xsl:call-template name="output-message">
  132. <xsl:with-param name="id" select="'DOTX046W'"/>
  133. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$shapeval"/></xsl:with-param>
  134. </xsl:call-template>
  135. </xsl:template>
  136. <xsl:template match="*" mode="ditamsg:area-element-missing-coords">
  137. <xsl:call-template name="output-message">
  138. <xsl:with-param name="id" select="'DOTX047W'"/>
  139. </xsl:call-template>
  140. </xsl:template>
  141. </xsl:stylesheet>