Subject: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.
Subject:Group parent elements in target XML Author:(Deleted User) 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.
Subject: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.