Subject: RE: RE: fn:contains multiple strings to compare with
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 5 Nov 2008 08:40:53 -0000
|
> You could use a trick. Sequences returned from a sequence
> expression are always flattened and concatenated. So:
>
> for $city in ('Hamburg', 'Coblenz', 'Aachen') return (if
> (contains('Hamburger', $city)) then true() else ())
>
> ...returns true(), because the empty sequences are simply
> discarded.
Not a good idea. If the input was "von Hamburg nach Aachen" the result would
be (true(), true()), and applying boolean() to that result gives an error.
And you don't need a trick here anyway, because
some $city in ('Hamburg', 'Coblenz', 'Aachen') satisfies (contains($input,
$city))
solves the problem perfectly well.
Or, if you prefer brevity, you can write
exists(('Hamburg', 'Coblenz', 'Aachen')[contains($input, .)])
Michael Kay
http://www.saxonica.com/
| Current Thread |
Tony Nassar - 5 Nov 2008 02:22:02 -0000
- Michael Kay - 5 Nov 2008 08:41:20 -0000 <=
|
|