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
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
(Deleted User) 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.

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

   
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.