|
Home >Online Product Documentation >Table of Contents >Calling Boolean Functions Calling Boolean FunctionsThis section describes the Boolean functions that you can call in a query. The operations you can perform are Converting an Object to BooleanIn some situations, you might want to force a Boolean comparison. The XPath processor performs a Boolean comparison if either operand is a Boolean value. Consequently, if neither operand is a Boolean value, call the boolean() function on one operand to convert it to a Boolean value. The XPath processor automatically converts the other operand to a Boolean value. The format of the boolean() function is
boolean boolean(object)
The boolean() function converts its argument to Boolean as follows:
l A number is false if and only if it is one of the following:
m Positive zero
m Negative zero
m NaN (not a number)
l A node set is false if and only if it is empty.
l A string is false if and only if its length is 0.
The boolean() function is useful in comparisons. For example, the following query returns b elements that either contain both c and d elements as children or contain neither c nor d elements as children: This query is equivalent to the following query: Obtaining Boolean ValuesTo obtain the opposite Boolean value, call the not() function. The format is The not() function returns true if its argument is false, and returns false if its argument is true. For example, the following query finds all authors who have publications but no degrees or awards: To obtain the value true, call the true() function. The format is The true() function returns true. To obtain the value false, call the false() function. The format is The false() function returns false. Determining the Context Node LanguageTo determine whether the language of the context node is the language you expect it to be, call the lang() function. The format is The lang() function returns true or false depending on whether the language of the context node as specified by the xml:lang attribute is the same as, or is a sublanguage of, the language specified by the argument string. The language of the context node is determined by the value of the xml:lang attribute on the context node or, if the context node has no xml:lang attribute, by the value of the xml:lang attribute on the nearest ancestor of the context node that has an xml:lang attribute. If there is no such attribute, then lang() returns false. If there is such an attribute, lang() returns true in the following situations:
l The attribute value is equal to the argument string.
l The attribute value has a suffix starting with a dash (-) such that the attribute value is equal to the argument string if you ignore the suffix.
In both situations, case is ignored. For example:
lang("en")
This returns true if the context node is any of these elements:
l <para xml:lang="en"/>
l <div xml:lang="en"><para/></div>
l <para xml:lang="EN"/>
l <para xml:lang="en-us"/>
|