Output of xsl: variable value with xsl: problem value

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

I'm trying to set up some hard-coded banners to be a little cleaner, so I thought it would be nice to create <xsl:variable> containing a link to the banner and image code, and then use <xml:value-of> in different places, where is the banner 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 does not give the expected result. The image of the path, etc. Valid, but it just doesn't spit anything. Any text added before or after the <a> tag displays correctly, but nothing happens between the <a> tags.

What I misunderstood about <xsl:variable> and how I could do it better (except to "correctly" and pull advertisements from the database, etc., which I would prefer ...).

+7
variables xslt
source share
1 answer

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

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

+7
source share

All Articles