Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  XML (Extensible Markup Language)

Comparisons


The = sign is used for equality; != is used for inequality. Alternatively, $eq$ and $ne$ can be used for equality and inequality.

Two operands are supplied for a comparison operation: the vector or scalar that is to be compared (the left side value, or lvalue), and the scalar value (the right side value, or rvalue) against which to compare. The rvalue must either be a scalar or a value that can be cast at run time to a scalar.

If the lvalue of a comparison is a set, "any" semantics are used for the comparison operators. That is, the result of a comparison is true if any item in the set meets the condition.

The lvalue of an expression cannot be a literal. That is, "3" = a is not allowed. If the rvalue is an attribute, the text(lvalue) is compared to the text(rvalue).

All elements and attributes are strings, but are automatically cast as integer values for numeric comparisons. Literal numeric values are cast to long or double types during comparison operations as shown in the following table.

Literal typeComparisonExample
Stringtext(lvalue) op text(rvalue)a < foo
Integer(long) lvalue op (long) rvaluea < 3
Real(double) lvalue op (double) rvaluea < 3.1

Single or double quotation marks can be used for string delimiters in expressions. This makes it easier to construct and pass XSL patterns from within scripting languages.

When comparing element values, the value() method is implied. That is, last-name < "foo" implies last-name!value() < "foo".

Examples

Find all author elements whose last name is Bob:

author[last-name = "Bob"]

author[last-name $eq$ "Bob"]

Find all author elements where the first last-name is Bob:

author[last-name[0] = "Bob"]

Find all authors where the from attribute is not equal to "Harvard":

degree[@from != "Harvard"]

degree[@from $ne$ "Harvard"]

Find all authors where the last name is the same as the /guest/last-name element:

author[last-name = /guest/last-name]

Find all authors whose text is "Matthew Bob":

author[. = "Matthew Bob"]

Binary Comparison Operators

A set of binary comparison operators compares numbers and strings and returns Boolean results. $lt$, $le$, $gt$, and $ge$ are used for less than, less than or equal, greater than, and greater than or equal. These same operators are also available in a case-insensitive form: $ieq$, $ine$, $ilt$, $ile$, $igt$, and $ige$.

Single or double quotation marks can be used for string delimiters in expressions. This makes it easier to construct and pass XSL patterns within scripting languages.

The Microsoft implementation supports the symbols <, <=, >, and >= as valid shortcuts for $lt$, $le$, $gt$, and $ge$, respectively.

Examples

Find all author elements whose last name is "Bob" and whose price is > 50:

author[last-name = "Bob" $and$ price $gt$ 50]

Find all authors where the from attribute is not equal to "Harvard":

degree[@from != "Harvard"]

Find all authors whose last name begins with "M" or greater:

author[last-name $ge$ "M"]

Find all authors whose last name begins with "M", "m", or greater:

author[last-name $ige$ "M"]

Find the first three books (0, 1, 2):

book[index() $le$ 2]

See Also

Sample Data, Examples


Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site