xsl:variable 作为其他 xsl 标记的 xpath 值 [英] xsl:variable as xpath value for other xsl tag
问题描述
我在使用 xsl:variable
时遇到问题.我想创建一个变量,其值取决于另一个 XML 节点属性的值.这工作很好.但是,当我尝试使用代表 XPath 的字符串值创建变量时,当我尝试在稍后的 XSL 标记中将其用作 XPath 时,它就不起作用了.
I'm having issues with xsl:variable
. I want to create a variable with a value that depends on the value of another XML node attribute. This working good. But when I try to create a variable with a string value that represents XPath, it just doesn't work when I try to use it as XPath in a later XSL tag.
<xsl:variable name="test">
<xsl:choose>
<xsl:when test="node/@attribute=0">string/represent/xpath/1</xsl:when>
<xsl:otherwise>string/represent/xpath/2</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="$test">
[...]
</xsl:for-each>
我试过:如何在 xsl if 中使用 xsl 变量和xsl:for-each selection using xsl:variable 的问题.但没有结果.
I tried: How to use xsl variable in xsl if and trouble with xsl:for-each selection using xsl:variable. But with no results.
推荐答案
如果像这种情况那样事先知道那些路径,那么你可以使用:
If those path are known in advance like this case, then you can use:
<xsl:variable name="vCondition" select="node/@attribute = 0"/>
<xsl:variable name="test" select="actual/path[$vCondition] |
other/actual/path[not($vCondition)]"/>
这篇关于xsl:variable 作为其他 xsl 标记的 xpath 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!