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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.