1
votes

I've to add an image from a servlet and then add this into a xsl.

This servlet have a getUrl method that return a base64 url.

I've tried this, but isn't correct:

java:

Transformer _Transformer = tFactory.newTransformer(style);

tFactory.setAttribute("imageChart", "ChartCreator?chartConfig=" + ChartPdfDecoder.getURL(chartConfig));

xsl:

<fo:block margin-left="1cm" margin-top="0.2cm" height="265px" width="310px">
    <fo:external-graphic src="url('$imageChart')"/>
</fo:block>

Who can help me?

Thanks

2
if the url is only returning the data, it probably will not work. you need the data: scheme and mimetype also.Kevin Brown

2 Answers

0
votes

You have one problem with this line...

<fo:external-graphic src="url('$imageChart')"/>

Because of the use of single apostrophes here, it will be literally looking for the url the "$imageChart". What you probably intended was for the value of the variable $imageChart to be written out by the XSLT at this point. The correct syntax is this..

<fo:external-graphic src="url('{$imageChart}')"/>

The curly braces here are Attribute Value Templates, and indicate an expression to be evaluated, rather than output literally.

Of course, you do need to ensure the variable/paramater $imageChart is being set to the correct URL for the image.

0
votes

You need to answer the question "What is the value of $imageChart?" ... if imageChart is a variable containing the Base64 encoded image as implied then you would need to use a data: scheme for the actually src attribute like below and you need to set the mimetype of the actual image ($mimetype in below stylesheet):

     <fo:external-graphic>
        <xsl:attribute name="src">
            <xsl:text>url('data:</xsl:text>
            <xsl:value-of select="$mimetype"/>                
            <xsl:text>;base64,</xsl:text>
            <xsl:value-of select="$imageChart"/>
            <xsl:text>')</xsl:text>
        </xsl:attribute>
    </fo:external-graphic>