为什么我的 XSLT 变量没有替换它们的值? [英] Why aren't my XSLT variables substituting their values?
问题描述
我正在尝试使用 XSLT 变量,但没有取得多大成功,希望我只是在做一些愚蠢的事情.
I am trying to use XSLT variables and not having much success, hopefully I'm just doing something dumb.
我有以下代码片段:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
version="1.0">
<xsl:template match="/">
<xsl:variable name="config" select="query/@config"></xsl:variable>
所以我希望有一个变量 'config' 设置为我的顶级元素 'query' 的 'config' 属性的值.
so I expect there to be a variable 'config' set to the value of the 'config' attribute of my top-level element 'query'.
然后我尝试稍后在样式表中使用该变量,例如:
I then try to use the variable later in my stylesheet, for example:
<a href="localhost/test?go">
{$config}
</a>
但我在输出 HTML 文档中看到的输出是:
but the output I see in my output HTML document is:
<a href="localhost/test?go">
{$config}
</a>
所以该值没有像我预期的那样被替换.
so the value has not been substituted as I would have expected.
我认为这几乎是最简单的情况,所以我在做蠢事!请帮忙,谢谢!
I think this is pretty much the simplest case there could be, so I'm doing domething stupid! Please help, thanks!
更新感谢所有回复的人,我误解了我是在属性中工作还是在外部工作的不同上下文.很好地解决了我的问题!
UPDATE thanks to all who responded, I misunderstood the different contexts of whether I was working in an attribute or outside. Sorted my problem out nicely!
如果可以的话,我会接受两个答案,一个是我的,另一个是@Aaron Digulla,它解释了属性.
If I could I would accept two answers, the one I have, and @Aaron Digulla's, which explained the attributes thing.
推荐答案
在你的样式表中你必须使用:
In your stylesheet you must use:
<xsl:value-of select="$config"/>
代替:
{$config}
这篇关于为什么我的 XSLT 变量没有替换它们的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!