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
Dominic VieiraSubject: Group parent elements in target XML
Author: Dominic Vieira
Date: 19 Apr 2007 03:50 PM
I have a question regarding how to format a target XML.
I have 2 source XML documents that have a parent-child relationship ( a common field in both files). Is there a way to map the 2 documents such that the target file will group the parent record and display only once for all corresponding child records.
For example,
<root>
<parent>
<child/>
<child/>
<child/>
</parent>
<parent>
<child/>
<child/>
<child/>
</parent>
</root>

Currently, when I link the two using the FLWOR the parent repeats for each child element.
<root>
<parent>
<child/>
</parent>
<child/>
<parent>
<child/>
</parent>
</root>
Thanks.

Postnext
Alberto MassariSubject: Group parent elements in target XML
Author: Alberto Massari
Date: 23 Apr 2007 12:41 PM
Hi Dominic,
could you post the full XML files? Just from seeing a generic structure, with no values, it's not clear to me the type of grouping you want to achieve.

Thanks,
Alberto

Postnext
Dominic VieiraSubject: Group parent elements in target XML
Author: Dominic Vieira
Date: 23 Apr 2007 12:54 PM
Find attached
1. XML Source
2. XML Source
3. XSD Target

XQuery File
-----------
<BAI_Format>
{
for $Batch in doc('file:///c:/WLB/CDS/Sample%20Extract%20Files/BAI/BatchHeader.xml')/BAIFormat/Batch,
$BatchDetail in /BAI_Format/BatchDetail
where $Batch/BatchNo = $BatchDetail/BatchNo
return
<BatchHeader>
{$Batch/RecordType/text()}
{$Batch/BatchNo/text()}
{$Batch/ItemNumber/text()}
{$Batch/LockboxNo/text()}
{$Batch/LockboxNo/text()}
{$Batch/DepositDate/text()}
{$Batch/TranDest/text()}
{$Batch/TranOrigin/text()}
<BatchDetail>
{$BatchDetail/RecordType/text()}
{$BatchDetail/BatchNo/text()}
{$BatchDetail/ItemNo/text()}
{$BatchDetail/ItemNo/text()}
{$BatchDetail/CheckAmt/text()}
{$BatchDetail/RT/text()}
{$BatchDetail/DDA/text()}
{$BatchDetail/CheckNo/text()}
</BatchDetail>
</BatchHeader>
}
</BAI_Format>

The common element in both XML files is BatchNo, which I would like to group so that the batchHeader element displays once for all associated detail BatchDetail elements.

Thanks,
Dominic


DocumentBatchHeader.xml
XML Source 1

DocumentBatchDetails.xml
XML Source 2

DocumentBAI_Target.xsd
Target XSD

Postnext
Alberto MassariSubject: Group parent elements in target XML
Author: Alberto Massari
Date: 24 Apr 2007 09:47 AM
Hi Dominic,
if you want to do grouping, you need to use distinct-values, like in this example:

<BAI_Format>
{
for $id in fn:distinct-values(doc('BatchHeader.xml')/BAIFormat/Batch/BatchNo)
let $Batch:=doc('BatchHeader.xml')/BAIFormat/Batch[BatchNo=$id]
return
<BatchHeader>
{$Batch/RecordType/text()}
{$Batch/BatchNo/text()}
{$Batch/ItemNumber/text()}
{$Batch/LockboxNo/text()}
{$Batch/LockboxNo/text()}
{$Batch/DepositDate/text()}
{$Batch/TranDest/text()}
{$Batch/TranOrigin/text()}
{
for $BatchDetail in /BAI_Format/BatchDetail[BatchNo=$id]
return
<BatchDetail>
{$BatchDetail/RecordType/text()}
{$BatchDetail/BatchNo/text()}
{$BatchDetail/ItemNo/text()}
{$BatchDetail/ItemNo/text()}
{$BatchDetail/CheckAmt/text()}
{$BatchDetail/RT/text()}
{$BatchDetail/DDA/text()}
{$BatchDetail/CheckNo/text()}
</BatchDetail>
}
</BatchHeader>
}
</BAI_Format>

Hope this helps,
Alberto

Posttop
Dominic VieiraSubject: Group parent elements in target XML
Author: Dominic Vieira
Date: 25 Apr 2007 12:10 PM
Thank-you!

 
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.