Search code examples
xmlxsltxlsapache-fop

How to insert image data from xml into xsl template?


I am converting xml to PDF with an xsl template, using Apache-FOP.

I have the following xml structure:

<image>
    <type>image/png</type>
    <data>iVBORw0KGgoAAAANS...</data>
</image>

And a template like:

<fo:external-graphic content-height="60pt" height="auto" width="auto"
                     src="url(data:<type>;base64,<data>)"/>

How do I insert data and type into the template?

Is there a better way to insert image as data from an xml?


Solution

  • Assuming your code is inside of an xsl:template match="image", to populate the attribute value from the child elements, use attribute value templates src="url(data:{type};base64,{data})".