【问题标题】:Outputting value of xsl:variable with xsl:value-of problem输出 xsl:variable 的值与 xsl:value-of 问题
【发布时间】:2010-03-08 13:28:34
【问题描述】:

我想我可能对<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>

但这并没有产生我期望的输出。图像路径等是有效的,但这根本不会吐出任何东西。在&lt;a&gt; 标记之前或之后添加的任何文本都可以正确显示,但&lt;a&gt; 标记之间没有任何内容。

我对@9​​87654328@ 有什么误解以及如何才能更好地做到这一点(除了“正确”地做到这一点并从数据库中提取广告等我更喜欢......)。

【问题讨论】:

    标签: xslt variables value-of


    【解决方案1】:

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

    您希望&lt;xsl:copy-of select='$banner1' /&gt; 复制结果树片段。

    【讨论】:

    • 非常感谢! xsl 很新,我没有看到我应该做的不同。干杯!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    相关资源
    最近更新 更多