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"]
               

            

XSL-List

The XSL-List forum is a valuable learning resource for the Extensible Stylesheet Language (XSL), covering the XSL specification, XSL processor implementations, and XSL user questions. Get this free XSL resource delivered to your inbox today.

Hotels, Casinos & Resorts That Use Stylus Studio

What's more romantic than a vacation for two and the world's best XML IDE at your finger tips? Nothing, that's why these hotels, casinos, & resorts are using Stylus Studio to help you get on your dream vacation.

XML Validator

Stylus Studio has a built-in XML validator that supports industry-standard DTD and XML Schema validators including MSXML 4.0 SAX, MSXML 4.0 DOM, Microsoft .NET XML Parser (System.XML), Xerces-J 2.5.1, XSV 2.6, etc. Validate XML with Stylus Studio.

XSD Documentation Generator

Stylus Studio®'s XSD Editor includes an integrated XSD documentation generator, allowing you to easily publish XML content models defined in XSD in a convenient, HTML format.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member