Re: Combine sub elements in identical elements

MessageThe particular query would be easily handled 
if there was a groupby construct.
Look at issue 168 in the XQuery document. 
The WG welcomes your feedback on the open
issues, and those who raised issue 168 would
appreciate your feedback on that issue
in particular. 

As Peter and others pointed out, the alternative
for grouping is to do it with nested queries. 


  ----- Original Message ----- 
  From: Peter Fankhauser 
  To: www-ql@w3.org 
  Sent: Monday, February 18, 2002 12:53 PM
  Subject: FW: Combine sub elements in identical elements


  Another try with a different send-address...

  Peter.
  -----Original Message-----
  From: Peter Fankhauser [mailto:fankhaus@infonyte.com] 
  Sent: Montag, 18. Februar 2002 14:56
  To: 'Chen Yabing'; 'www-ql@w3.org'
  Subject: RE: Combine sub elements in identical elements


  It appears that you want to
  depict only projects for which there exist suppliers for which there exist
  parts with a price > 110, within those projects you only want to return suppliers
  for which there exist parts with a price > 110, within those suppliers you
  only want to return the parts with a price > 110.

  One way to accomplish this in XQuery is by a nested query.

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

  In fact, this corresponds to the (presumed) logic of your query
  pretty well. If you're happy with possibly empty suppliers and
  projects, you can leave out the predicates with [.//price].

  Hope this clarifies,


  Peter

    -----Original Message-----
    From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf Of Chen Yabing
    Sent: Montag, 18. Februar 2002 13:21
    To: 'www-ql@w3.org'
    Subject: 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 16:53:40 UTC