i have below 2 xml file(fruit.xml and toy.xml).I wanted to use xquery to retrieve the fruit and toy that is produce by the country Japan.
the expected result should be like below toys need to be list out first before the fruit.
<JapanProduct>
<Prod type="Toy">Digimon<Prod>
<Prod type="Toy">Doll<Prod>
<Prod type="Fruit">Peach<Prod>
</JapanProduct>
below is the xquery code that i wrote and is currently stuck here.how can i produce the expected result as above?
for $f in doc("Fruit.xml")//Produce
for $t in doc("Toy.xml")//Produce
where $f[Country="Japan"] and $t[Country="Japan"]
return element JapanProduct {attribute Prod{if ($f[country=Japan"])then }
Fruit.XML
<fruitsOrigin>
<Produce>
<Country>Australia</Country>
<Prod>Kiwi</Prod>
<Size>M</Size>
</Produce>
<Produce>
<Country>China</Country>
<Prod>Pear</Prod>
<Size>M</Size>
</Produce>
<Produce>
<Country>Japan</Country>
<Prod>Peach</Prod>
<Size>L</Size>
</Produce>
</fruitsOrigin>
Toy.XML
<ToyMaker>
<Produce>
<Country>Australia</Country>
<Prod>Lego</Prod>
<cost>$15</cost>
</Produce>
<Produce>
<Country>Japan</Country>
<Prod>Doll</Prod>
<cost>$20</cost>
</Produce>
<Produce>
<Country>Japan</Country>
<Prod>Digimon</Prod>
<cost>$17</cost>
</Produce>
</ToyMaker>
Below works..
You can give a try here http://basex.org/products/live-demo/