1

当我应用转换时,我得到一个异常:表达式必须评估为节点集。

  <xsl:for-each select = "some expression">
    <xsl:variable name="a0" select="some expression"/>
    <xsl:variable name="a1" select="some expression"/>
    <xsl:variable name="a2" select="some expression"/>

    <xsl:for-each select="$a0 | $a1 | $a2">
        <xsl:value-of select="."/>
        <xsl:if test="position()!=last()">,</xsl:if>
    </xsl:for-each>

  </xsl:for-each>

现在,如果我要使用 if 语句并将其放在第一个循环的级别,则可以正确应用转换。

如果问题在于表达式“$a0 | $a1 | $a2”不被视为节点集,我如何使用 XSLT 1.0 实现类似的目标?

4

1 回答 1

3

正如错误所述,在 XSLT 1.0 中,您不能使用联合运算符来连接还不是节点的操作数。

如果您使用的是支持node-set()功能的 XSLT 处理器,您可以这样做:

<xsl:for-each select="exsl:node-set($a0) | exsl:node-set($a1) | exsl:node-set($a2)">
    <xsl:value-of select="."/>
    <xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>

但如果你要这样做,你不妨这样做:

<xsl:value-of select="concat($a0, ',', $a1, ',', $a2)" />

Judging from a recent question you made, perhaps you have tons of variables, in which case perhaps your design needs some rethinking. If you could provide some specifics instead of generic placeholders, perhaps someone could advise you on a different approach.

于 2013-02-04T20:51:36.470 回答