XSLT 1.0 xsl:boolean选择test

时间:2012-10-19 12:39:45

标签: asp.net xslt xslt-1.0

我有一个带有序列化数据注释的对象。它有一个布尔属性,它是真的(用调试器测试)所以100%确定,但是当我在xslt中有这个时:

<xsl:for-each select="order/Coupons/orderedCoupons" >
    <tr>
        <td>Discount <xsl:value-of select="@code"/></td>
        <td>
            <xsl:choose>
                <xsl:when test="@isperc='true'">
                    <xsl:value-of select="@disvalue"/>%
                </xsl:when>
                <xsl:otherwise>Epic fail
                    &#8364; <xsl:value-of select="format-number(@disvalue, '#.###,00', 'euro')" />
                </xsl:otherwise>
            </xsl:choose>
        </td>
    </tr>
</xsl:for-each>

它始终显示史诗失败,因此测试始终失败。我也试过了:

  • @ isperc = '真'
  • @ isperc = 1
  • 布尔型(@isperc)
  • @isperc = true()

更多背景信息:它是一个asp.net对象,我通过构建数据注释进行序列化。 .Net中的XSLT支持仅为1.0。

编辑coupon.cs

的一部分
[XmlAttribute("isperc")]
public bool IsPerc
{
    get { return _isPerc; }
}

它不可空,但正如第二个评论家指出的那样,<xsl:value-of select="@isperc"/>的价值是多少,它似乎是空的。它在html中解析为什么都没有。不是空格,不是空等,这很奇怪,因为布尔值是true ...

edit2 这也没有输出<xsl:value-of select="string(@isperc)"/>,所以这也失败<xsl:when test="string(@isperc) = 'true'">

1 个答案:

答案 0 :(得分:2)

<xsl:when test="@IsPerc = true()">

应匹配C#布尔类型。

我看到的解决方法是将布尔值转换为数字,但是;

<xsl:when test="number(@IsPerc) > 0">