开发者

Outputting value of xsl:variable with xsl:value-of problem

开发者 https://www.devze.com 2022-12-22 10:33 出处:网络
I think I may have a misunderstanding of <xsl:variable\\> and <xsl:value-of\\> so perhaps someone can correct me!

I think I may have a misunderstanding of <xsl:variable\> and <xsl:value-of\> so perhaps someone can correct me!

I'm attempting to tweak some hardcoded banners to be a bit cleaner so I thought it would be a good idea to create an <xsl:variable> containing the banner link and image code, then use <xml:value-of> at the various places where the banner is needed. For example:

<!-- 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>

But this isn't producing the output I expect. The images path etc is valid, but this just spits out nothing at all. Any text added before or after the <a> tag appears correctly, but nothing between the <a> tags Themselves.

What have I misunderstood abo开发者_Go百科ut <xsl:variable> and how could I do this better (other than doing it "properly" and pulling adverts from a database etc. which I'd prefer...).


The value you are selecting with xsl:value-of is the string value of the variable.

You want <xsl:copy-of select='$banner1' /> to copy the result tree fragment.

0

精彩评论

暂无评论...
验证码 换一张
取 消