如何获取节点集子节点的值?

How to get value of a child of node-set?

我在我的 XSLT 中使用一个变量来 select 更正节点,然后我想使用这个变量来检索它的子节点:

<xsl:variable name="CorrectNode">
              <xsl:choose>
                 <xsl:when test="$Formula='14'">
                    <xsl:value-of select="f:node14" />
                  </xsl:when>
                  <xsl:when test="$Formula='15'">
                     <xsl:value-of select="f:node15" />
                  </xsl:when>
              </xsl:choose>
</xsl:variable>
<Revenue>
   <xsl:value-of select="msxsl:node-set($CorrectNode)/f1:revenueValue" />
</Revenue>

然而,它没有输出任何东西。如果我有:

<xsl:value-of select="msxsl:node-set($CorrectNode)" />

<xsl:copy-of select="msxsl:node-set($CorrectNode)" />

然后输出值或节点,但如何访问其子节点?

此代码段将变量设置为由一个文本节点组成的结果树片段,其值为相应元素的字符串值。该变量 引用元素本身,仅引用其 字符串值 .

但是您根本不需要 RTF 和 node-set 函数,因为您可以使用适当的谓词直接 select 来完成,因为 test 表达式是不依赖于上下文(无论当前上下文是 f:node15 元素还是它的父元素,像 $Formula = '15' 这样的测试给出相同的值):

<xsl:variable name="CorrectNode"
              select="f:node14[$Formula = '14'] | f:node15[$Formula = '15']" />

这样变量就是对原始元素的引用,您可以使用 XPath 从那里导航。