Frage

when I apply the transform I get an exception: expression must evaluate to a node-set.

  <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>

Now, if I were to take the if statement and place it at the level of the first loop, the transform can be applied properly.

If the problem is that the expression "$a0 | $a1 | $a2" is not considered a nodeset, how can I accomplish a similar goal using XSLT 1.0?

War es hilfreich?

Lösung

As the error states, in XSLT 1.0, you can't use the union operator to join operands that aren't already nodes.

If you're using an XSLT processor that supports the node-set() function, you can do this:

<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>

But if you're going to do that, you might as well do this:

<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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top