Problem with adding padding and border to an image

Here should go questions about transforming XML with XSLT and FOP.
rww
Posts: 23
Joined: Wed Jul 24, 2013 12:40 am

Problem with adding padding and border to an image

Post by rww »

I'm trying to add padding and a border around images but cannot get my code to work correctly. The code is currently as follows:

Code: Select all

 <xsl:attribute-set name="image">
<xsl:attribute name="border">
<xsl:if test="@outputclass='Border'">
<xsl:attribute name="padding"> 5px </xsl:attribute>
<xsl:attribute name="border"> solid 1pt blue </xsl:attribute>
</xsl:if>
</xsl:attribute>
</xsl:attribute-set>
So, if the outputclass is 'Border' I want an image with 5px padding with a 1pt border. However, the border is coming out as 5px thick. If I move the padding line to after the </xsl:attribute> line the padding and border are drawn correctly, but then all images have padding, which is not what I require.

Can anyone tell me what the problem is and how to fix it?

Thanks
Radu
Posts: 9434
Joined: Fri Jul 09, 2004 5:18 pm

Re: Problem with adding padding and border to an image

Post by Radu »

Hi,

This is for DITA to PDF, right?
You could do something like:

Code: Select all

<xsl:attribute-set name="image">
<xsl:attribute name="border">
<xsl:choose>
<xsl:when test="@outputclass='Border'">
solid 1pt blue
</xsl:when>
<xsl:otherwise>0pt</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="padding">
<xsl:choose>
<xsl:when test="@outputclass='Border'">
5px
</xsl:when>
<xsl:otherwise>0px</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:attribute-set>
In what you tried you nested an xsl:attribute inside another one which is incorrect.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
rww
Posts: 23
Joined: Wed Jul 24, 2013 12:40 am

Re: Problem with adding padding and border to an image

Post by rww »

Yes, DITA to PDF. Your code worked beautifully, thanks.
Post Reply