W3C home > Mailing lists > Public > www-xpath-comments@w3.org > January to March 2002

Comparisons in XPath 2.0

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 2 Jan 2002 18:17:41 -0500 (EST)
Message-ID: <9413834142.20020102224000@jenitennison.com>
To: www-xpath-comments@w3.org
CC: xsl-list@lists.mulberrytech.com
Hi,

For all that there are lots of ways of comparing values in XPath 2.0,
there doesn't seem to be one that compares sequences.

If you have something like:

  <line start="0 300" end="300 0" />

where start and end both have typed values - @start is the sequence of
two integers (0, 300) and @end is the sequence of two integers (300,
0). In this particular language, @start and @end are x,y coordinates.
How can you work out whether start and end have the same value?

  @start eq @end

returns an error because the typed values for each node return a
sequence with more than one value.

  @start = @end

also returns an error (I think), because it is equivalent to:

  some $s in (@start) satisfies (some $e in (@end) satisfies $e eq $s)

and @start eq @end returns an error.

I think it would make more sense to say that eq can only be used with
single nodes, but that it compares sequences of simple values with a
xf:sequence-deep-equal() comparison (each simple typed value is the
same as the simple typed value with the same index in the compared
sequence). Thus:

  @start = @end

would be equivalent to:

  @start eq @end

which would be equivalent to:

  (0, 300) eq (300, 0)

which would be false. If @end were (0, 300) instead, the comparison
would be:

  (0, 300) eq (0, 300)

which would be true.

Cheers,

Jeni
---
Jeni Tennison
http://www.jenitennison.com/
Received on Thursday, 3 January 2002 07:45:12 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 3 October 2007 16:05:54 GMT