使用xsl:value-of问题输出xsl:variable的值

xan*_*xan 7 xslt variables value-of

我想可能有一个误解<xsl:variable\>,并<xsl:value-of\>因此也许有人可以纠正我!

我试图调整一些硬编码的横幅以使其更清洁,所以我认为创建一个<xsl:variable>包含横幅链接和图像代码,然后<xml:value-of>在需要横幅的各个地方使用是个好主意.例如:

<!-- Global variable in my xslt file. There are a bunch of these... -->
<xsl:variable name="banner1">
    <a href="http://www.link.com/" title="Title" target="_blank">
        <img width="120" height="506" src="/images/banners/image.gif" alt="alt" />
    </a>
</xsl:variable>

<!-- Then when used: -->
<xsl:when test="blah'">
    <xsl:value-of select="$banner1"/>
</xsl:when>
Run Code Online (Sandbox Code Playgroud)

但这并没有产生我期望的输出.图像路径等是有效的,但这根本不会吐出任何东西.<a>标签之前或之后添加的任何文本都会正确显示,但<a>标签之间没有任何内容.

我误解了什么,我<xsl:variable>怎么能更好地做到这一点(除了"正确地"并从数据库中提取广告等我更喜欢...).

Lac*_*che 7

使用xsl:value-of选择的值是变量的字符串值.

您想要<xsl:copy-of select='$banner1' />复制结果树片段.