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: Grouping in xQurey (Nested For command)
Author: Julio de la Vega
Date: 18 Dec 2007 10:13 AM
Hi *,

I have a little problem with my xQuery development.
My input xml is:

<10>
<Field1>xxxx</Field1>
<Field2>xxxx</Field2>
<Field3>xxxx</Field3>
</10>

<20>
<Field1>xxxx</Field1>
<Field2>xxxx</Field2>
</20>

<20>
<Field1>xxxx</Field1>
<Field2>xxxx</Field2>
</20>

<10>
<Field1>xxxx</Field1>
<Field2>xxxx</Field2>
<Field3>xxxx</Field3>
</10>

<20>
<Field1>xxxx</Field1>
<Field2>xxxx</Field2>
</20>

Records type '20' can appear n times.



I need to change my xml to group records type 20 as children of their previous record type 10:



<10>

<20>

<20>

</10>

<10>

<20>

</10>





My xQuery development is getting all records type 20 together per every record 10. Could you please help me to understand why? I need to group the records type 20 with is records type 10.

This is my actual development

let $doc := doc('converter:file:///\\Server-hps\tecnico\Proyectos\Caja Madrid\Xpresso\Stylus\Desarrollos\SICAV\XQUERY\SICAVXQUERY.conv?file:///\\Server-hps\tecnico\Proyectos\Caja Madrid\Xpresso\Stylus\Desarrollos\SICAV\XQUERY\SICAVXQUERYReducido.txt')
return
<root>
{
for $REG_10 in $doc/root/REG_10

return
<REG_10>
{$REG_10}
{
for $REG_20 in $doc/root/REG_20

return
<Datos>
{$REG_20}
</Datos>
}
</REG_10>
}
</root>


Thanks in advance



Regards


Postnext
Minollo I.Subject: Grouping in xQurey (Nested For command)
Author: Minollo I.
Date: 18 Dec 2007 11:42 AM
The easiest way to do this is probably to leverage the "<<" and ">>" XPath operators; you can change your code into something like the following (note the "where" condition on the second "for"):

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
<Datos>
{$REG_20}
</Datos>
}
</REG_10>
}

</root>

Postnext
Julio de la VegaSubject: Grouping in xQurey (Nested For command)
Author: Julio de la Vega
Date: 18 Dec 2007 12:00 PM
Thank you, it works and does what I need.
My problem now is to undertand what you have done because I have to apply it in other parts of my development. Where can I find information about the commands you have used? Could you please 'tanslate' it and give me an overview?

Thanks in advance

Postnext
Minollo I.Subject: Grouping in xQurey (Nested For command)
Author: Minollo I.
Date: 18 Dec 2007 12:32 PM
Read the "where" condition:
where $REG_20 >> $REG_10 and (empty($REG_10/following-sibling::REG_10) or ($REG_20 << $REG_10/following-sibling::REG_10[1]))

It's saying: consider only those $REG_20's that follow $REG_10 in document order (the ">>" operator - http://www.w3.org/TR/xpath20/#id-node-comparisons), and that appear before (the "<<" operator) in document order relative to the next REG_10 node (retrieved using the followin-sibling axis - http://www.w3.org/TR/xpath20/#axes); the empty(...) expression only checks the special case when there are no further REG_10 elements, at the end of the document.

Postnext
Julio de la VegaSubject: Grouping in xQurey (Nested For command)
Author: Julio de la Vega
Date: 19 Dec 2007 02:33 AM
Thank you Minollo,

I will review the information you have sent to me

Thanks again

Postnext
Julio de la VegaSubject: Grouping in xQuery (Nested For command)
Author: Julio de la Vega
Date: 19 Dec 2007 07:10 AM
Hi again,

According to the same issue, 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

Posttop
Minollo I.Subject: Grouping in xQuery (Nested For command)
Author: Minollo I.
Date: 19 Dec 2007 08:59 AM
I'm assuming you have asked the same question here: http://www.stylusstudio.com/ssdn/default.asp?action=9&read=7264&fid=57#22779

Let's keep the conversation in a single place then.

 
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.