Search code examples
c#xmlxsltxslt-2.0xsl-choose

xsl:choose Expression must evaluate to a node-set


I am working with C# and XSLT 2.0. I am having problem with one of templates, it seems to be falling over <xsl:choose> statement. Values passed are Key - Value pairs and all but two values are decimals. Intention is to format decimals with 2 decimal places and , on thousands while integers should be without decimal places.

<xsl:choose>
      <xsl:when test="Key='Seller count' || Key='Buyer count'">
        <td>
          <xsl:value-of select="format-number(Value, '0')"/>
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td>
          <xsl:value-of select="format-number(Value, '#,##0.00')"/>
        </td>
      </xsl:otherwise>
    </xsl:choose>` 

is giving me

An exception of type 'System.Xml.Xsl.XslTransformException' occurred in     System.Data.SqlXml.dll but was not handled in user code

Additional information: Expression must evaluate to a node-set.

Which is somewhat surprising as it gets opening and closing <td> </td> into both when and otherwise.

I am assuming that this is something obvious that I am failing to see.


Solution

  • XSLT 1.0 has the union operator | which works on node-sets and the boolean or operator which works with boolean values. There is no || operator in XSLT, neither in 1.0 nor in 2.0. If you want to write a boolean or expression use <xsl:when test="Key='Seller count' or Key='Buyer count'"> .