counting FLWR results

I had hoped to do something like:

count(for $scene in document(“/db/myplay.xml”)/PLAY/ACT/SCENE
where $scene/SPEECH[SPEAKER=“ONEGUY”] and $scene/SPEECH[SPEAKER=“OTHERGUY”]
return 0)
unfortunately though, when there are no results meeting the where clause the statement being counted returns false… which count() evaluates as 1 (counter intuitive I think)

Any ideas on a way to rewrite this to give the ‘correct’ response of 0 when there are no shared scenes? I’ve been racking my brain for a day now.


Thanks!

Kevin
kevin.is-a-geek.net

Hi Kevin,

unfortunately you do not tell us which XQuery implementation you use.
I tried to reproduce this using Tamino 4.2 and everything seems fine,
i.e. a FLWR that returns nothing contains zero results, and thus
count(FLWR) is zero. count() however yields a static type error since
count is supposed to have one argument. What tool are you using ?

Regards,
Juliane.

Should implementation matter? surely this behavior would be in the spec…

I’m using eXist 1.0

I got around this by changing it up to:

count(for $scene in document(“/db/myplay.xml”)/PLAY/ACT/SCENE/[SPEECH/SPEAKER=“ONEGUY”]
where $scene/SPEECH[SPEAKER=“OTHERGUY”]
return 0)

The statements look equivalent to me but this one works… ideas why?

Kevin

Hi Kevin,

yes the second query is equivalent except that the / preceding the [
is wrong, I guess it is just a spelling mistake. I don’t know much
about eXist but perhaps it does some optimization w.r.t. where
clauses that is slightly buggy. These things happen. Your question
might be interesting for the eXist guys.

Regards, Juliane.

PS: Of course, implementation matters. If you tried this one with
Tamino, we should do something about it.