Anders
Anders

Reputation: 11

How to use xsl:value-of as src for fo:external-graphic?

I'm fairly new to XSL-FO, and what I'm trying is probably not the ideal way to solve this.

I've got a few icons stored in a local directory. I need to use the path to these icons dynamically for the src of fo:external-graphic.

<fo:external-graphic src='xsl:value-of select="article[@index=1]/data/subscriber-B-10'  width="100px" height="90px" content-height="scale-up-to-fit"  display-align="center" text-align="center"></fo:external-graphic>

I have tried different variations of the path in subscriber-B-10.

"subscriber-B-10": "url('file:///C:/Users/Administrator/icons/icon1.bmp')",
"subscriber-B-10": "file:///C:/Users/Administrator/icons/icon1.bmp",

The last one with src='url("xsl:value-of select="article[@index=1]/data/subscriber-B-10")'

Using the path directly to one of the icons is working:

src='url("file:///C:/Users/Administrator/icons/icon1.bmp")

Upvotes: 0

Views: 587

Answers (1)

Tony Graham
Tony Graham

Reputation: 8068

Look up 'Attribute Value Templates'. The XSLT 1.0 definition is at https://www.w3.org/TR/1999/REC-xslt-19991116#attribute-value-templates (but hopefully you are using the more recent XSLT 2.0 or XSLT 3.0).

You can use an attribute value template to get the string value of your XPath by putting the XPath between { and } in your literal attribute value:

<fo:external-graphic
  src="{article[@index=1]/data/subscriber-B-10}"
  width="100px" height="90px" content-height="scale-up-to-fit"
  display-align="center" text-align="center" />

Upvotes: 1

Related Questions