How the XPath Processor Evaluates Comparisons

A query can compare values of elements. For example:

last-name [. = "foo"] 
               

            

The XPath processor compares the value of each last-name element in the current context with the value "foo". The result of each comparison is a Boolean value. The XPath processor returns the last-name elements for which the comparison yields true.

As mentioned before in Filtering Results of Queries, the XPath processor evaluates filters with respect to a context. For example, the expression book[author] means for every book element that is found, determine whether it has an author child element. Likewise, book[author = "Bob"] means for every book element that is found, determine whether it contains an author child element whose value is "Bob".

Comparisons are case sensitive. For example, "Bob" and "bob" are not considered to be equal.

Remember that comparisons return Boolean values. For example:

/bookstore/book/author/last-name="Bob"
               

            

You might think that this query returns authors whose last name is "Bob". But this is not the case. This query returns a single Boolean value. It tests each last-name element to determine if its value is "Bob". As soon as the XPath processor finds a last-name element that tests true, it returns true. If no nodes test true, this query returns false.

To obtain author elements whose last name is "Bob", enclose the comparison in a filter as follows:

/bookstore/book/author[last-name="Bob"]
               

            

Support for DataDirect SequeLink

Learn about Stylus Studio's support for DataDirect SequeLink, an end-to-end database middleware solution that provides a universal thin client for ODBC, JDBC, ADO or .NET, providing flexibility for both client- and server-based deployments.

The Stylus Studio Advantage

Read in their own words, why customers have decided to make the switch to Stylus Studio, the World's best XML editor.

Investments and Financial Companies That Use Stylus Studio

Stylus Studio provides XML tools & components to leading investment and financial companies! See which top investment and financial companies are banking on Stylus Studio 2006 to simplify their dollars and cents.

DTD Generator

Stylus Studio's DTD Generator supports the automatic generation and association of both internal and external DTDs based on XML instance documents.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member