I am getting my desired schema. But the one thing i need to do is to eliminate duplicate values. Hence I use distinct values, but what that function does is it displays all the values within one element.
Input Schema:
<?xml version="1.0" encoding="UTF-8"?>
<hotel>
<food>
<name>Burger</name>
<cost>20</cost>
</food>
<food>
<name>Pizza</name>
<cost>20</cost>
</food>
<food>
<name>Cola</name>
<cost>5</cost>
</food>
<food>
<name>Lemonade</name>
<cost>5</cost>
</food>
<food>
<name>Ice Cream</name>
<cost>10</cost>
</food>
<food>
<name>Cookies</name>
<cost>10</cost>
</food>
</hotel>
Output presently:
<type>
<cost>01</cost>
<food>burger fries cola</food>
</type>
Desired:
<type>
<cost>01</cost>
<food>burger</food>
<food>fries</food>
<food>cola</food>
</type>
Basically get all the food for that price.
My Xquery is as follows:
let $cost:= doc("Untitled7.xml")/hotel/food/cost
for $unique in distinct-values(doc("Untitled7.xml")/hotel/food/cost)
let $food:= distinct-values(doc("Untitled7.xml")hotel/food[cost=$unique]/name)
where $unique = $cost
return
<type>
<year>{$unique}</year>
<food>{$food}</food>
</type>
Any help will be appreciated :)