Lullaby
Lullaby

Reputation: 437

Set a image url dynamically into a xsl file

I want to create an xsl file (for a xslt transformation to xsl:fo using an xml) How can I display a image whose url is stored in the xml file? I can use variables

<fo:block-container top="5mm" height="20mm" left="0mm" width="75mm">
      <fo:block margin-top="10mm" margin-left="50mm">
        <fo:external-graphic display-align="center" src="url('{$imageUrl}')" content-width="75mm"></fo:external-graphic>
      </fo:block>
    </fo:block-container>

But how can I set the variable's value from a tag from the xml file?

Sample XML from comment:

<?xml version="1.0" encoding="UTF-8" ?>
<doc> 
  <title>Simple test</title>
  <image>
    <i>colour_logo.jpg</i>
  </image>
  <body>
    <question>
      <p>Is the sky blue?</p>
    </question>
    <question> 
      <p>Is the grass blue?</p> 
    </question> 
  </body> 
</doc>

Upvotes: 2

Views: 4216

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52858

You can replace {$imageUrl} with {/doc/image/i}.

  <fo:block-container top="5mm" height="20mm" left="0mm" width="75mm">
    <fo:block margin-top="10mm" margin-left="50mm">
      <fo:external-graphic display-align="center" src="url('{/doc/image/i}')" content-width="75mm"></fo:external-graphic>
    </fo:block>
  </fo:block-container>

Upvotes: 3

Related Questions