代码之家  ›  专栏  ›  技术社区  ›  xan

用xsl:value问题输出xsl:variable的值

  •  7
  • xan  · 技术社区  · 15 年前

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

    但这并不能产生我所期望的输出。图像路径等是有效的,但这只是吐出什么都没有。在 <a> 标签显示正确,但在 <A & GT; 标记自己。

    我误解了什么 <xsl:variable> 我怎样才能做得更好(除了“正确”地做和从数据库中提取广告等等,我更喜欢…)。

    1 回复  |  直到 15 年前
        1
  •  7
  •   Lachlan Roche    15 年前

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

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