Question

I'm using Apache FOP Version 1.1 to build a pdf (by command line) Here is my XSL that's working fine

<fo:table-row >
    <fo:table-cell >
        <fo:block >
            <fo:external-graphic content-height="9mm" content-width="9mm" height="10mm" width="10mm" scaling="non-uniform" src="url(./images/pict2.jpg)" />
        </fo:block>
    </fo:table-cell>
</fo:table-row >

If I try to use a template declared in this way

<xsl:template name="myRow" >
    <xsl:param name="imgUrl"/>
    <fo:table-row >
        <fo:table-cell >
            <fo:block >
                <fo:external-graphic content-height="9mm" content-width="9mm" height="10mm" width="10mm" scaling="non-uniform" src="url($imgUrl)"/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row >
</xsl:template>

and I call it as

<xsl:call-template name="myRow">
    <xsl:with-param name="imgUrl" select="'./images/pict2.jpg'" />
</xsl:call-template>

no image is shown. If I write select="./images/pict2.jpg" (without single quotes) the imgUrl parameter is null How can I pass the url and get it working ?

Was it helpful?

Solution

If you want to refer to a variable in an attribute you need to use Attribute Value Templates.

Try this line instead in your template

<fo:external-graphic content-height="9mm" content-width="9mm" height="10mm" width="10mm" 
                     scaling="non-uniform" src="url({$imgUrl})"/>

The curly braces indicate an expression to be evaluated, rather than output literally (which is what is happening to your code at the moment. It is literally outputting the text $imgUrl, rather than the value of the variable).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top