[英]Setting image src in xsl-fo
我有xml文件,這些文件將提供圖像的文件名。
<task>
<header>Diagram</header>
<image>image.png</image>
</task>
在xls-fo中,我嘗試使用:
<xsl:template match="image">
<fo:block>
<fo:external-graphic>
<xsl:attribute name="src">./<xsl:value-of select="image"/></xsl:attribute>
</fo:external-graphic>
</fo:block>
</xsl:template>
這不會產生錯誤,但是圖像不會出現在pdf中。 為了使圖像出現,我必須對文件名進行硬編碼,如下所示:
<xsl:attribute name="src">./image.png<xsl:value-of select="image"/></xsl:attribute>
如何從xml獲取文件名,以使用xsl中提供的路徑。
您的模板已匹配image
。 在其中,您位於該元素的上下文中 ,該元素沒有image
child ,而只是您要選擇的文本節點 。 當您在其中使用<xsl:value-of select="image"/>
時,實際上是在嘗試類似task/image/image
。
將您的value-of
image
替換value-of
.
(節點的字符串值)或text()
(其文本內容)。 任何選項將具有相同的結果。
<xsl:template match="image">
<fo:block>
<fo:external-graphic>
<xsl:attribute name="src">./<xsl:value-of select="."/></xsl:attribute>
</fo:external-graphic>
</fo:block>
</xsl:template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.