使用 xsl:value-of 问题输出 xsl:variable 的值
我想我可能对
和
有误解,所以也许有人可以纠正我!
我正在尝试调整一些硬编码的横幅,使其更简洁,因此我认为创建一个包含横幅链接和图像代码的
是个好主意,然后使用 < code>
<!-- 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>
但这并没有产生我期望的输出。图像路径等是有效的,但这根本没有吐出任何内容。 标记之前或之后添加的任何文本都会正确显示,但
标记之间没有任何内容。
我对
有什么误解,我怎样才能做得更好(除了“正确地”做并从数据库中提取广告等,我更喜欢......) 。
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 about <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...).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用 xsl:value-of 选择的值是变量的字符串值。
您希望
复制结果树片段。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.