Hi Raj,
I am responding to the mailinglist so that maybe other people can benefit from your question as well.
This is not a BaseX bug, indeed it returns the correct result. The problem is with your query and the scope of your selection. The variable $i contains the whole document, so basically it does not iterate much. You are then filtering out each document, which does not have a country with the id f0_136. As the whole factbook.xml does have one such element, it is passed on and all the country names are returned.
What you instead want to do is to iterate over each country, not over each document. So the following will work as expected:
for $i in doc("etc/factbook.xml")/mondial/country where $i/@id = 'f0_136' return $i/name
You can also simplify this using a predicate:
for $i in doc("etc/factbook.xml")/mondial/country[@id = 'f0_136'] return $i/name
or even
doc("etc/factbook.xml")/mondial/country[@id = 'f0_136']/name
Cheers, Dirk
On 07/05/2013 10:01 AM, Rajabrata Chaudhuri wrote:
Hi Dirk,
I was hoping you could help me with a problem. Based on our previous discussion, I started experimenting with Base-X, but am having trouble with even the basic FLOWR queries applying the "WHERE" clause, which for some reason is always returning every node in the XML document. As an example, I tried the factbook.xml that comes with the Base-X install with the following query:
for $i in doc("etc/factbook.xml") where $i/mondial/country/@id = 'f0_136' return $i/mondial/country/name
<name>Albania</name> <name>Andorra</name> <name>Austria</name> <name>Belarus</name> <name>Belgium</name> <name>Bosnia and Herzegovina</name> <name>Bulgaria</name> <name>Croatia</name> <name>Czech Rep.</name> <name>Czech Republic</name> <name>Denmark</name> <name>Estonia</name> <name>Faroe Islands</name> <name>Finland</name> <name>France</name> ...
The result is coming back with every country when it should just return Albania. Can you help me with this? Is this some kind of Base-X bug, because I am not sure what I am doing wrong here.
Thanks Raj
Thanks Dirk. Yeah, I got that to work too, I guess it makes sense. It is behaving differently for me in ML though, which is weird.
Maybe, I am just stupid today.
Raj
________________________________ From: Dirk Kirsten dk@basex.org To: Rajabrata Chaudhuri rajabrata@yahoo.com; BaseX basex-talk@mailman.uni-konstanz.de Sent: Friday, July 5, 2013 1:38 AM Subject: Re: Base-X FLOWR Expressions Not Working?
Hi Raj,
I am responding to the mailinglist so that maybe other people can benefit from your question as well.
This is not a BaseX bug, indeed it returns the correct result. The problem is with your query and the scope of your selection. The variable $i contains the whole document, so basically it does not iterate much. You are then filtering out each document, which does not have a country with the id f0_136. As the whole factbook.xml does have one such element, it is passed on and all the country names are returned.
What you instead want to do is to iterate over each country, not over each document. So the following will work as expected:
for $i in doc("etc/factbook.xml")/mondial/country where $i/@id = 'f0_136' return $i/name
You can also simplify this using a predicate:
for $i in doc("etc/factbook.xml")/mondial/country[@id = 'f0_136'] return $i/name
or even
doc("etc/factbook.xml")/mondial/country[@id = 'f0_136']/name
Cheers, Dirk
On 07/05/2013 10:01 AM, Rajabrata Chaudhuri wrote:
Hi Dirk,
I was hoping you could help me with a problem. Based on our previous discussion, I started experimenting with Base-X, but am having trouble with even the basic FLOWR queries applying the "WHERE" clause, which for some reason is always returning every node in the XML document. As an example, I tried the factbook.xml that comes with the Base-X install with the following query:
for $i in doc("etc/factbook.xml") where $i/mondial/country/@id = 'f0_136' return $i/mondial/country/name
<name>Albania</name> <name>Andorra</name> <name>Austria</name> <name>Belarus</name> <name>Belgium</name> <name>Bosnia and Herzegovina</name> <name>Bulgaria</name> <name>Croatia</name> <name>Czech Rep.</name> <name>Czech Republic</name> <name>Denmark</name> <name>Estonia</name> <name>Faroe Islands</name> <name>Finland</name> <name>France</name> ...
The result is coming back with every country when it should just return Albania. Can you help me with this? Is this some kind of Base-X bug, because I am not sure what I am doing wrong here.
Thanks Raj
basex-talk@mailman.uni-konstanz.de