ut-d.xsl 6.8 KB

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