Combine sub elements in identical elements

Hi,

 it seems that XQuery cannot place elements together even if they have same
parent elements in the result. I mean that the result will produce two
identical elements for each sub elements.

For example, the source document:
<db>
	<project jno="j001">
		<supplier sno="s001">
			<part pno="p001" >
				<price>190</price>
			</part>
		</supplier>
		<supplier sno="s002">
			<part pno="p001">
				<price>110</price>
			</part>
		</supplier>
	</project>
	<project jno="j002">
		<supplier sno="s002">
			<part pno="p002">
				<price>120</price>
			</part>
		</supplier>
	</project>
</db>

the query is:

FOR      $j IN document("spj.xml")//project, 
         $s IN $j/supplier, 
         $p IN $s/part
WHERE    $p/price >100
return
           <project jno = {$j/@jno}>
                    <supplier sno = {$s/@sno}>
                          <part pno = {$p/@pno}>
                                 {$p/price}
                          </part>
                    </supplier>
           </project>

and the result is:

<project jno="j001">    
    <supplier sno="s001">      
      <part pno="p001">	
        <price>190</price>
      </part>
    </supplier>
  </project>
  <project jno="j001">    
    <supplier sno="s002">      
      <part pno="p001">	
        <price>110</price>
      </part>
    </supplier>
  </project>
  <project jno="j002">    
    <supplier sno="s002">      
      <part pno="p002">	
        <price>120</price>
      </part>
    </supplier>
  </project>
</xql:result>

In the ideal situation, the query result should be identical to the source
document. but there are two project whose jno is "j001". 
If I want to produce a result which will combine elements under the
identical parent elements together so that there are only one parent
elements. How can I do based on the above query?

Thank you!

Received on Monday, 18 February 2002 07:21:03 UTC