Reputation: 17
Question: How to get the src
attribute from the img
element, then copy the src
's value it into a variable, and then set the variable as the src
for the fo:external-graphic
element?
Assume that I have a XML document with an image that looks like this:
<diffreport>
<css />
<diff>
<p>
<span class="diff-html-removed" id="removed-diff-0" previous="first-diff"
changeId="removed-diff-0" next="added-diff-0">
<img alt="" id="Rxed6OQAKXfCYA"
src="D:\udu\img1.jpg" changeType="diff-removed-image" />
</span>
</p>
</diff>
Note: Assume the src
paths for every img
element will be dynamic.
I confirmed that this piece of code bellow works ok, but it is not good because it is hard coded. I would really like to know how to replace the "url('D:\udu\img1.jpg')" with a variable so that the code is dynamic.
<!-- Image -->
<xsl:template match="img">
<fo:external-graphic
src="url('D:\udu\img1.jpg')"></fo:external-graphic>
</xsl:template>
Is there any way to doing this? Thank you. :)
Upvotes: 0
Views: 1440
Reputation: 8068
Use an attribute value template that will be evaluated to get the value of the @src
from your XML. See https://www.w3.org/TR/xslt#attribute-value-templates
<!-- Image -->
<xsl:template match="img">
<fo:external-graphic src="url('{@src}')" />
</xsl:template>
Upvotes: 0
Reputation: 7173
you can try
<xsl:template match="img">
<fo:external-graphic
src="{concat('file:///', translate(@src, '\', '/'))}" />
</xsl:template>
which will get D:\udu\img1.jpg
and have it called as file:///D:/udu/img1.jpg
Upvotes: 1