XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Julio de la VegaSubject: Two level grouping
Author: Julio de la Vega
Date: 19 Dec 2007 08:46 AM
Originally Posted: 19 Dec 2007 08:47 AM
Hi *,

In my actual development I am grouping a first level using this code:

let $doc := doc(...)
return
<root>
{
for $REG_10 at $REG_10-startPos in $doc/root/REG_10
return
<REG_10>
{$REG_10}
{
for $REG_20 at $REG_20-pos in $doc/root/REG_20
where $REG_20 >> $REG_10 and (empty($REG_10/following-sibling::REG_10) or ($REG_20 << $REG_10/following-sibling::REG_10[1]))
return
$REG_20
}
</REG_10>
}
</root>

Now I need to do a secong grouping inside the first grouping. I need to group the records type 20 acording one of its children (the criteria for secod grouping is one of the children of 20)

This is the layout that I need:

<10>
<group_20_1>
<20>...</20>
<20>...</20>
<20>...</20>
</group_20_1>

<group_20_2>
<20>...</20>
<20>...</20>
</group_20_2>
</10>

<10>
...

Could you please give me an overview about how to do it?

Thanks again

Regards

Julio

Postnext
Minollo I.Subject: Two level grouping
Author: Minollo I.
Date: 19 Dec 2007 09:00 AM
What is the second grouping based on? Can you provide a few more details?

Postnext
Julio de la VegaSubject: Two level grouping
Author: Julio de la Vega
Date: 19 Dec 2007 09:10 AM
Originally Posted: 19 Dec 2007 09:09 AM
Hi Minollo,

Second gouping is based in a child of record type 20. Let me show you more information:

Original input
<10>
</10>
<20>
<field1>X</field1>
<field2></field2>
...
</20>
<20>
<field1>X</field1>
<field2></field2>
...
</20>
<20>
<field1>X</field1>
<field2></field2>
...
</20>
<20>
<field1>Y</field1>
<field2></field2>
...
</20>
<20>
<field1>Y</field1>
<field2></field2>
...
</20>
<10>
</10>
<20>
...

First, we were grouping nodes 20 according their previous REG_10. Now, I need to group nodes 20 using field1 values

Target Output

<10>
<group_20_X>
<20>...</20>
<20>...</20>
<20>...</20>
</group_20_X>

<group_20_Y>
<20>...</20>
<20>...</20>
</group_20_Y>
</10>

<10>
...

Thanks again

Postnext
Minollo I.Subject: Two level grouping
Author: Minollo I.
Date: 19 Dec 2007 09:34 AM
This looks like a generic XQuery grouping question. Take a look at http://www.xquery.com/tips_and_tricks/value_based_grouping.html for some details (and at http://www.xquery.com/tips_and_tricks/ in general). In your specific case, you could do something like this (where I picked one of the sub-elements as an example).

BTW, please note that this is the Stylus Studio development network; we usually don't provide detailed help for language specific problems/questions; we provide help/guidance for our XML products. Future generic XQuery questions should be asked on a different kind of forum, like for example xquery-talk (http://x-query.com/mailman/listinfo/talk). Thanks.


...
let $all_REG_20s := for $REG_20 at $REG_20-pos in $doc/root/REG_20
where $REG_20 >> $REG_10 and (empty($REG_10/following-sibling::REG_10) or ($REG_20 << $REG_10/following-sibling::REG_10[1]))
return $REG_20
for $unique_REG_20 in distinct-values($all_REG_20s/TIPRE6)
return
element {concat("REG_20_", $unique_REG_20)} {
for $REG_20 in $all_REG_20s[TIPRE6 = $unique_REG_20]
return
<Datos>
{$REG_20}
</Datos>
}
}
...

Posttop
Julio de la VegaSubject: Two level grouping
Author: Julio de la Vega
Date: 19 Dec 2007 11:15 AM
Thank you Minollo,

I will use a different forum for this kind of questions

Thanks again

Regards

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.