Set a image url dynamically into a xsl file

流过昼夜 提交于 2019-12-11 03:17:21

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/3840326/set-a-image-url-dynamically-into-a-xsl-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!