Question
· Jan 26, 2022

Using XSLT to add background image

I have a PDF ZEN report module that I'm using  XslFoXslt to highlight the table cell.

What I need is for a particular value to add a background image to the <item> that is calling the XSLFoXslt

The code I have is the following but all that happens is the color. 

XData XslFoXslt
{
<xsl:template name="HighLight">
<xsl:param name="Value"/>

<xsl:if test="$Value = 400">
<xsl:attribute name='background-image'>url("images/trash-icon.png")</xsl:attribute>
<xsl:attribute name='background-repeat'>no-repeat</xsl:attribute>
<xsl:attribute name='color'>#ffffff</xsl:attribute> </xsl:if>

</xsl:template>
}
 

Product version: Caché 2018.1
Discussion (7)1
Log in or sign up to continue

Hi Con

I think your problem might be that background-image and background-repeat are CSS properties, not HTML attributes.  Color works because it is an HTML attribute (although you should use the CSS style property for this as well these days).

Try:

<xsl:if test="$Value = 400">
     <xsl:attribute name='style'>background-image: url("images/trash-icon.png"); background-repeat: no-repeat;</xsl:attribute>
     <xsl:attribute name='color'>#ffffff</xsl:attribute>
</xsl:if>

If that works then you might want to consider using a class attribute to reference a stylesheet rather than including a style attribute directly, but that's another matter.

George