code-srv-test/dita-ot-3.6/plugins/org.lwdita/xsl/ut-d.xsl
2021-03-23 22:38:58 +00:00

156 lines
7 KiB
XML

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
exclude-result-prefixes="ditamsg">
<xsl:template match="*[contains(@class,' ut-d/imagemap ')]" name="topic.ut-d.imagemap">
<div>
<xsl:call-template name="commonattributes"/>
<xsl:call-template name="setidaname"/>
<xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
<!-- the image -->
<image usemap="#{generate-id()}">
<!-- Border attribute defaults to 0 -->
<xsl:apply-templates select="." mode="imagemap-border-attribute"/>
<!-- Process the 'normal' image attributes, using this special mode -->
<xsl:apply-templates select="*[contains(@class,' topic/image ')]" mode="imagemap-image"/>
</image>
<map name="{generate-id(.)}" id="{generate-id(.)}">
<xsl:for-each select="*[contains(@class,' ut-d/area ')]">
<area>
<!-- if no xref/@href - error -->
<xsl:choose>
<xsl:when test="*[contains(@class,' topic/xref ')]/@href">
<!-- special call to have the XREF/@HREF processor do the work -->
<xsl:apply-templates select="*[contains(@class, ' topic/xref ')]" mode="imagemap-xref"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="ditamsg:area-element-without-href-target"/>
</xsl:otherwise>
</xsl:choose>
<!-- create ALT text from XREF content-->
<!-- if no XREF content, use @HREF, & put out a warning -->
<xsl:choose>
<xsl:when test="*[contains(@class, ' topic/xref ')]">
<xsl:variable name="alttext">
<xsl:apply-templates select="*[contains(@class, ' topic/xref ')]/node()[not(contains(@class, ' topic/desc '))]" mode="text-only"/>
</xsl:variable>
<xsl:attribute name="alt">
<xsl:value-of select="normalize-space($alttext)"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="normalize-space($alttext)"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="ditamsg:area-element-without-linktext"/>
</xsl:otherwise>
</xsl:choose>
<!-- if not valid shape (blank, rect, circle, poly); Warning, pass thru the value -->
<xsl:variable name="shapeval">
<xsl:value-of select="*[contains(@class,' ut-d/shape ')]"/>
</xsl:variable>
<xsl:attribute name="shape">
<xsl:value-of select="$shapeval"/>
</xsl:attribute>
<xsl:variable name="shapetest">
<xsl:value-of select="concat('-',$shapeval,'-')"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains('--rect-circle-poly-default-',$shapetest)"/>
<xsl:otherwise>
<xsl:apply-templates select="." mode="ditamsg:area-element-unknown-shape">
<xsl:with-param name="shapeval" select="$shapeval"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
<!-- if no coords & shape<>'default'; Warning, pass thru the value -->
<xsl:variable name="coordval">
<xsl:value-of select="*[contains(@class,' ut-d/coords ')]"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="string-length($coordval)>0 and not($shapeval='default')">
<xsl:attribute name="coords">
<xsl:value-of select="$coordval"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="ditamsg:area-element-missing-coords"/>
</xsl:otherwise>
</xsl:choose>
</area>
</xsl:for-each>
</map>
<xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
</div>
</xsl:template>
<!-- Set the border attribute on an imagemap; default is to always use border="0" -->
<xsl:template match="*[contains(@class,' ut-d/imagemap ')]" mode="imagemap-border-attribute">
<xsl:attribute name="border">0</xsl:attribute>
</xsl:template>
<!-- In the context of IMAGE - call these attribute processors -->
<xsl:template match="*[contains(@class, ' topic/image ')]" mode="imagemap-image">
<xsl:call-template name="commonattributes"/>
<xsl:call-template name="setid"/>
<xsl:apply-templates select="@href|@height|@width"/>
<xsl:choose>
<xsl:when test="*[contains(@class, ' topic/longdescref ')]">
<xsl:apply-templates select="*[contains(@class, ' topic/longdescref ')]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="@longdescref"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="*[contains(@class,' topic/alt ')]">
<xsl:attribute name="alt">
<xsl:apply-templates select="*[contains(@class,' topic/alt ')]" mode="text-only"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="@alt">
<xsl:attribute name="alt">
<xsl:value-of select="@alt"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- In the context of XREF - call it's HREF processor -->
<xsl:template match="*[contains(@class, ' topic/xref ')]" mode="imagemap-xref">
<xsl:attribute name="href">
<xsl:call-template name="href"/>
</xsl:attribute>
<xsl:if test="@scope='external' or @type='external' or ((@format='PDF' or @format='pdf') and not(@scope='local'))">
<xsl:attribute name="target">_blank</xsl:attribute>
</xsl:if>
</xsl:template>
<xsl:template match="*" mode="ditamsg:area-element-without-href-target">
<xsl:call-template name="output-message">
<xsl:with-param name="id">DOTX044E</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="*" mode="ditamsg:area-element-without-linktext">
<xsl:call-template name="output-message">
<xsl:with-param name="id">DOTX045W</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="*" mode="ditamsg:area-element-unknown-shape">
<xsl:param name="shapeval" select="*[contains(@class,' ut-d/shape ')]/text()"/>
<xsl:call-template name="output-message">
<xsl:with-param name="id">DOTX046W</xsl:with-param>
<xsl:with-param name="msgparams">%1=<xsl:value-of select="$shapeval"/></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="*" mode="ditamsg:area-element-missing-coords">
<xsl:call-template name="output-message">
<xsl:with-param name="id">DOTX047W</xsl:with-param>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>