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)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Viktor KramSubject: merging two xml documents
Author: Viktor Kram
Date: 13 Mar 2006 09:00 PM
Hello

I am a newbie with xslt and was wondering if I can get some help on merging two xml document to output a result document that would be used as a sync mechanism (add/delete) between the master.xml and input.xml, matching on the PackageId.

Any help is appreciated. Thanks.

Master.xml:
-----------
<PackageAction>
<PackageName>NBC</PackageName>
<PackageData>
<PackageElement>
<ID>PackageId</ID>
<value>1234</value>
</PackageElement>
</PackageData>
</PackageAction>

Input.xml:
---------
<Package>
<InteractionId>InteractionId_0</InteractionId>
<ActionDate>ActionDate_1</ActionDate>
<AccountId>AccountId_1</AccountId>
<PackageId>1234</PackageId>
</Package>

Postnext
Minollo I.Subject: merging two xml documents
Author: Minollo I.
Date: 13 Mar 2006 09:12 PM
Something like this?

<xsl:template match="/">
<table border="1">
<tbody>
<tr>
<td>
<xsl:value-of select="PackageAction/PackageName"/>
</td>
<td>
<xsl:value-of select="PackageAction/PackageData/PackageElement/ID"/>
</td>
<xsl:variable name="value" select="PackageAction/PackageData/PackageElement/value"/>
<xsl:variable name="packageInfo" select="document('input.xml')/Package[PackageId = $value]"/>
<td>
<xsl:value-of select="$packageInfo/InteractionId"/>
</td>
<td>
<xsl:value-of select="$packageInfo/ActionDate"/>
</td>
<td>
<xsl:value-of select="$packageInfo/AccountId"/>
</td>
</tr>
</tbody>
</table>
</xsl:template>

Postnext
Viktor KramSubject: merging two xml documents
Author: Viktor Kram
Date: 13 Mar 2006 11:01 PM
Thanks Minollo. I appreciate the help. It was good to start me with. My intention was to get an xml document based on a whether a corresponding package exists in the master document, if not, introduce a flag 'ADD', if the package did not exist in the input document, change the flag to 'DELETE', more on the terms like:

<Package>

<PackageAction>
<PackageName>NBC</PackageName>
<PackageData>
<PackageElement>
<ID>PackageId</ID>
<value>1234</value>
<SyncAction>ADD</SyncAction>
</PackageElement>
</PackageData>
</PackageAction>

<PackageAction>
<PackageName>ABC</PackageName>
<PackageData>
<PackageElement>
<ID>PackageId</ID>
<value>2345</value>
<SyncAction>DELETE</SyncAction>
</PackageElement>
</PackageData>
</PackageAction>

</Package>

Thanks for the help.

Posttop
Minollo I.Subject: merging two xml documents
Author: Minollo I.
Date: 13 Mar 2006 11:04 PM
Sure, you can use <xsl:choose>, like in...

<xsl:variable name="packageInfo" select="document('input.xml')/Package[PackageId = $value]"/>
<xsl:choose>
<xsl:when test="$packageInfo">
<!-- do something with $packageInfo -->
</xsl:when>
<xsl:otherwise>
<!-- do something else -->
</xsl:otherwise>
</xsl:choose>

   
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.