db2 - Filtering XML using multiple conditions of xquery -


hi have many xml files have structure like:

<mydoc>       <ec>          <spec>             <name>a para</name>             <para>a</para>             <val>40</val>          </spec>          <spec>             <name>input voltage</name>             <para>vin</para>             <val>40</val>          </spec>       </ec> </mydoc> 

i need filter out xml files has spec para=vin , val>30

what should xquery like? in db2 have far?

for $x in db2-fn:xmlcolumn('table.xmlcolumn')/mydoc 

so iterate on xml files , have mydoc element tag in $x how implement multiple conditions , return name of spec satisfies conditions?

there couple ways express this. xpath predicates:

for $x in db2-fn:xmlcolumn('table.xmlcolumn')/mydoc[ec/spec[para = 'vin' , val > 40]] 

or xquery's where clause. uses xpath predicates , think easier read:

for $x in db2-fn:xmlcolumn('table.xmlcolumn')/mydoc let $specs := $x/ec/spec ($spec[para = 'vin' , val > 40]) 

both should give same results.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -