[xquery-talk] using OR in xquery expression
jeff.dexter at rainingdata.com
Thu May 18 14:01:08 PDT 2006
Your query should work as you expect. I can't speak to why exist
isn't returning the correct results, but I've suggested a re-write below
that may work. The use of the combo predicate/where as well as re-iterating
over the data in $p while applying restrictions to $r may be why exist isn't
working for this query. I ran your query against TigerLogic and it ran fine.
The following query <em>may</em> work for you as it eliminates some
of the oddities, though I can't guarantee it models your original intent,
and I haven't tested it against exist.
for $r in //section
[@role="subject" and . ="Explanation"]
for $p in $r/sectioninfo/keywordset/keyword
[ @role = 'objrel' or @role = 'subrel' ]
where $p = 'scan-status'
I eliminated the combo predicate/where and simplified the secondary
ForExpr, so the query is a little simpler and should return your intended
result, but again, I haven't tried it against exist, so I can't guarantee it
will get you over the hump (but it's worth a try...)
Having said all that, if it turns out the OrExpr is the problem, you
can always try
@role = ( 'objrel', 'subrel' )
@role = 'objrel' or @role = 'subrel'
Anyway, there are a lot of ways to write this, which is why some
optimizers have differing degrees of luck in optimizing it the right way.
Chief Architect, TigerLogic
From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On Behalf Of
Sent: Thursday, May 18, 2006 3:28 AM
To: talk at xquery.com
Subject: [xquery-talk] using OR in xquery expression
Dear XQuery Experts,
Please consider the following XML extracts
Now please consider the following query below
for $r in //section where
$r/sectioninfo/keywordset/keyword[@role="subject"]= "Explanation" return
(for $p in //section where
Given this XQuery, the database returns only Extract B (where the objrel
value is "scan status") but does not return Extract A (where subrel
value is "scan status")
I am unable to understand why this is happening since I am using OR so
that either of the two expressions should return a result.
Please guide me on this.
FYI, I am using the exist XML DB.
Thanks and Regards
talk at xquery.com
More information about the talk