File: Data.xml
<order>
<car model="ACC">
<id>0001</id>
<name language="en">name 1</name>
</car>
<car model="BCC">
<id>0002</id>
<name language="en">name 2</name>
</car>
<car model="BCC">
<id>0003</id>
<name language="en">name 3</name>
</car>
</order>
File: Query.xquery
for $prod in (doc("Data.xml")/order/car)
return if ($prod/@model = 'ACC')
then <accessory>{data($prod/id)}</accessory>
else if ($prod/@model = 'WMN')
then <womens>{data($prod/id)}</womens>
else if ($prod/@model = 'MEN')
then <mens>{data($prod/id)}</mens>
else <other>{data($prod/id)}</other>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<accessory>0001</accessory>
<other>0002</other>
<other>0003</other>
|