如何创建一个布尔值? [英] How to create a boolean value?

查看:95
本文介绍了如何创建一个布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全新XSLT和不能工作在哪里,我用下面的code走错了。

I am totally new to XSLT and can't work out where I am going wrong with the following code.

<xsl:variable name="var" select="boolean('false')"/>

<xsl:if test="$var'">variable is true</xsl:if>

当它意味着是假它总是返回true。为什么呢?

It is always returning true when it is meant to be false. Why?

推荐答案

在中定义的是$ var变量的值:

The value of the $var variable as defined in:

&NBSP;&NBSP;&NBSP; &LT; XSL:变量名=VAR选择=布尔(假)/&GT;

   <xsl:variable name="var" select="boolean('false')"/>

&NBSP;&NBSP;&NBSP; 真()

   true()

这是因为在XPath的是一个普通的字符串,而不是假(),其中是布尔构造假()

This is because in XPath "false" is an ordinary string, as opposed to false(), which is the constructor for the boolean value false()

XPath中两个布尔值(请注意,他们正在构建的!):

The two boolean values in XPath are (note that they are constructed!):

&NBSP;&NBSP;&NBSP; 真() 假()

   true() and false()

将任何价值布尔拼写outin的的XPath规格的细节:

The detail of converting any value to boolean are spelled outin the XPath Spec.:

布尔 函数将其参数转换为布尔如下

"The boolean function converts its argument to a boolean as follows:


  • 一个数是当且仅当它真
    既不是正或负零
    也为NaN

  • a number is true if and only if it is neither positive or negative zero nor NaN

节点集是当且仅当它真
非空

a node-set is true if and only if it is non-empty

字符串为真当且仅当它
长度为非零

a string is true if and only if its length is non-zero

比四种基本类型以外的类型的对象被转换成的方式一个布尔值,取决于该类型

an object of a type other than the four basic types is converted to a boolean in a way that is dependent on that type "

在您的情况下,字符串假不是数字0,并具有积极的长度,因此,在上述第3项中的规则应用,产生真()

In your case the string "false" is not the number 0 and has a positive length, so the rule in the 3rd bullet above is applied, yielding true().

因此,在XSLT 1.0,其值定义一个变量 假() ,需要写的定义如下:

Therefore, to define a variable in XSLT 1.0, whose value is false(), one needs to write the definition as the following:

&NBSP;&NBSP;&NBSP; &LT; XSL:变量名=vMyVar选择=假()/&GT;

   <xsl:variable name="vMyVar" select="false()"/>

或者,如果你不完全记住这一点,你总是可以写:

or, if you don't exactly remember this, you could always write:

&NBSP;&NBSP;&NBSP; &LT; XSL:变量名=vMyVar选择=1 = 0/&GT;

   <xsl:variable name="vMyVar" select="1 = 0"/>

(指定任何前pression计算结果为假())和XSLT处理器将做的工作适合你。

(specify any expression that evaluates to false()) and the XSLT processor will do the work for you.

在XSLT 2.0它始终是最好明确指定类型的变量:

&NBSP;&NBSP;&NBSP; &LT; XSL:变量名=vMyVar为=XS:布尔选择=假()/&GT;

   <xsl:variable name="vMyVar" as="xs:boolean" select="false()"/>

这篇关于如何创建一个布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆