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
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext 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>

 
Topic Page 1 2 3 4 5 6 7 8 9 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.