xml - Xquery: Find the Makers such that every PC they produce has a price no more than 100 -
i'm trying path conditions "find makers such every pc produce has price no more 100" , "find names of makers produces @ least 2 pc’s speed of 3 or more". i'm using data pasted below.
i'm little lost , love example on how carry out.
with data:
<?xml version="1.0" encoding="utf-8"?> <products> <maker name="a"> <pc model="1001" price="2114"> <speed>2.66</speed> <ram>1024</ram> <harddisk>250</harddisk> </pc> <pc model="1002" price="995"> <speed>2.10</speed> <ram>512</ram> <harddisk>250</harddisk> </pc> <laptop model="2004" price="1150"> <speed>2.00</speed> <ram>512</ram> <harddisk>60</harddisk> <screen>13.3</screen> </laptop> <laptop model="2005" price="2500"> <speed>2.16</speed> <ram>1024</ram> <harddisk>120</harddisk> <screen>17.0</screen> </laptop> </maker> <maker name="e"> <pc model="1011" price="959"> <speed>l.86</speed> <ram>2048</ram> <harddisk>160</harddisk> </pc> <pc model="1012" price="649"> <speed>2.80</speed> <ram>1024</ram> <harddisk>160</harddisk> </pc> <laptop model="2001" price="3673"> <speed>2.00</speed> <ram>2048</ram> <harddisk>240</harddisk> <screen>20.1</screen> </laptop> <printer model="3002" price="239"> <color>false</color> <type>laser</type> </printer> </maker> <maker name="h"> <printer model="3006" price="100"> <color>true</color> <type>ink-jet</type> </printer> <printer model="3007" price="200"> <color>true</color> <type>laser</type> </printer> </maker> </products>
find makers such every pc produce has price no more [1000]
i changed 100 1000 since there isn't maker makes pc price under 100 in sample data.
another way read question is:
find maker's (/products/maker), that make pc ([pc]), that have no pc's price greater 1000 ([not(pc/@price > 1000)]).
all put together...
/products/maker[pc , not(pc/@price > 1000)] equivalent flwr statement...
for $maker in /products/maker $maker/pc , not($maker/pc/@price > 1000) return $maker result (both xpath , flwr)...
<maker name="e"> <pc model="1011" price="959"> <speed>l.86</speed> <ram>2048</ram> <harddisk>160</harddisk> </pc> <pc model="1012" price="649"> <speed>2.80</speed> <ram>1024</ram> <harddisk>160</harddisk> </pc> <laptop model="2001" price="3673"> <speed>2.00</speed> <ram>2048</ram> <harddisk>240</harddisk> <screen>20.1</screen> </laptop> <printer model="3002" price="239"> <color>false</color> <type>laser</type> </printer> </maker> find names of makers produces @ least 2 pc’s speed of [2] or more
i changed 3 2 since there isn't maker makes 2 or more pc's speed of 3 or more in sample data.
another way read question is:
find names of makers (/products/maker/@name) that produce @ least 2 pc's ([count(pc) >= 2]) with speed of 2 or more ([speed >= 2]).
all put together...
/products/maker[count(pc[speed >= 2]) >= 2]/data(@name) equivalent flwr statement...
for $maker in /products/maker count($maker/pc[speed >= 2]) >= 2 return data($maker/@name) result (both xpath , flwr)...
a
Comments
Post a Comment