Re: [xsl] Comparing sequences

Subject: Re: [xsl] Comparing sequences
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 9 Feb 2006 14:44:00 +1100
On 2/9/06, cknell@xxxxxxxxxx <cknell@xxxxxxxxxx> wrote:
> Given two sequences where:
>
> $seq-a = 001,030,021,008
> and
> $seq-b = 005,030,026,009
>
> How do I write an expression that returns true if any item in $seq-a is
found in $seq-b?

One possible XPath expression is:

    empty($vS1[not(. = $vS2)])

However, this may sometimes raise an exception, depending on the types
of the two sequences.

Evaluating this expression (with Saxon8.6.1) on:

    5.0,030,026,009
and
  005,005,030,026,009,'xxx'

produces:
                 true()

However, evaluating the expression on:

   5.0,030,026,009
and
  '005',005,030,026,009,'xxx'

raises an exception (with Saxon8.6.1):

  "  XPTY0004: Cannot compare xs:string to xs:decimal
Transformation failed: Run-time errors were reported"

Obviously, getting true() in the first case above is not reliable, as
it depends on a given XPath2.0 processor support for lazy evaluation
and is most probably going to vary wildly accross different
processors.

This poses a new challenge in trying to write portable XPath 2.0
expressions -- people will need to evaluate their expressions on a
"dumb-enough" engine...


Let me predict:

  "Beaware of types"

will be one of the most popular sayings in the XPath2.0 era.


--
Cheers,
Dimitre Novatchev
---------------------------------------
The significant problems we have cannot be solved at the same level of
thinking with which we created them.

Current Thread