Specifying Boolean Expressions and Functions

This section provides information on how to specify Boolean expressions and functions in queries. It includes the following topics:

Using Boolean Expressions

You can specify Boolean expressions in the subqueries in filters. You specify the Boolean AND, OR, and NOT operators like this:

You can use parentheses to group collection specifications and operators for clarity or where the normal precedence is inadequate to express an operation.

Case Sensitivity

Operators are case sensitive. Spaces are not significant. You can omit them or include them for clarity.

Examples

The following query returns all authors who have at least one degree and one award:

author[degree and award] 
               

            

The next query finds all authors who have at least one degree or award and at least one publication:

author[(degree or award) and publication] 
               

            

Following is a query that finds all authors who have at least one degree and no publications:

author[degree and not(publication)] 
               

            

Calling Boolean Functions

This section describes the Boolean functions that you can call in a query. The operations you can perform are

Converting an Object to Boolean

In 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:

  • A number is false if and only if it is one of the following:
    • Positive zero
    • Negative zero
    • NaN (not a number)
  • A node set is false if and only if it is empty.
  • 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:

/a/b[boolean(c) = d]
               

            

This query is equivalent to the following query:

/a/b [(c and d) or (not(c) and not(d))]
               

            

Obtaining Boolean Values

To obtain the opposite Boolean value, call the not() function. The format is

boolean not(boolean) 
               

            

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:

author[not(degree or award) and publication] 
               

            

To obtain the value true, call the true() function. The format is

boolean true() 
               

            

The true() function returns true.

To obtain the value false, call the false() function. The format is

boolean false() 
               

            

The false() function returns false.

Determining the Context Node Language

To determine whether the language of the context node is the language you expect it to be, call the lang() function. The format is

boolean lang(string) 
               

            

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:

  • The attribute value is equal to the argument string.
  • 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:

  • <para xml:lang="en"/>
  • <div xml:lang="en"><para/></div>
  • <para xml:lang="EN"/>
  • <para xml:lang="en-us"/>

Stylus Studio Blogs

Blogging is the hottest fad on the Internet and Stylus Studio has jumped on the bandwagon. Bookmark these XML Blogs to keep up with all the latest XML buzz in the internet blogosphere. Includes RSS and Atom Feeds!

XML Differencing

Stylus Studio's integrated XML Differencing tool visually computes and analyzes any changes made to files or folders in a highly configurable, XML-aware fashion. Display text or tree views, with changes displayed in a merged view or side-by-side!

Using Stylus Studio's Database-to-XML Editor to Query and Update Relational Databases using SQL/XML

Watch and learn how easy it is to define relational-to-XML mappings for getting XML out of relational databases and updating databases from XML using industry-standard SQL/XML extensions and Stylus Studio's DB-to-XML data-source editor.

XML-to-XML Mapper

XML to XML mapping tools in Stylus Studio provide a powerful visual interface for mapping XML data from-and-to virtually any data format using industry-standard XSLT and XQuery technologies.

Stylus Most Wanted

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.