简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM