如何在XSLT 1.0中连接params?

时间:2013-02-28 19:50:26

标签: xslt

我使用的图像src作为变量传递,代码如下:

    <xsl:param name="a" />

<img width="300" height="270" src="{a}" />

这没问题,但我不能将图像放在根文件夹中,我需要将它们放在图像文件夹中,现在我花了很长时间尝试了很多东西,但是我怎么能这样做:

<img width="300" height="270" src="images/{a}" />

我尝试将“images /”存储为param字符串,然后尝试在{a}前面连接它,但无论我尝试什么,我都无法让它工作。任何想法如何做到这一点?

1 个答案:

答案 0 :(得分:2)

使用美元符号来引用您的变量。

示例

输入:

<a href="testImg.png"/>

变换:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="a">
       <xsl:call-template name="renderImg">
            <xsl:with-param name="a" select="@href"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="renderImg"> 
       <xsl:param name="a" />
       <img width="300" height="270" src="images/{$a}" />
    </xsl:template>
</xsl:stylesheet>

输出:

<img width="300" height="270" src="images/testImg.png" />