Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 22nd, 2009, 04:14 PM
Authorized User
 
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default Merge XML file data into one XML

Hi Guys,

I need help on following....


This is the Contact XML out
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Contact xmlns="urn:/crmondemand/xml/Contact/Data" xmlns:ns="urn:crmondemand/ws/ecbs/contact/10/2004" xmlns:p0="urn:crmondemand/ws/ecbs/contact/10/2004" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ModifiedById>AAFA-2M15UT</ModifiedById>
<Id>AAGA-3G1NHA</Id>
<AccountId>AAGA-3G1LK0</AccountId>
<stModified_By_User_ID>AAFA-2M125P</stModified_By_User_ID>
<ContactRole/>
<CustomObject2Id>AAGA-3G1N9U</CustomObject2Id>
</Contact>
This is User XML file...

Code:
<?xml version="1.0" encoding="UTF-8"?>
<UserQueryPage_Output xmlns="urn:crmondemand/ws/ecbs/user/10/2004" xmlns:p0="urn:crmondemand/ws/ecbs/user/10/2004" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="p0:UserQueryPage_Output">
- <ListOfUser lastpage="true" xmlns="urn:/crmondemand/xml/User/Data" xmlns:ns="urn:crmondemand/ws/ecbs/user/10/2004">
- <User>
<Id>AAFA-2M125P</Id>
<ExternalSystemId>7001</ExternalSystemId>
</User>
</ListOfUser>
</UserQueryPage_Output>
This is Address XML
CustomObject2Id XML form ContactId which is under One level from CustomObject2Id

Code:
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject2 xmlns="urn:/crmondemand/xml/customobject2" xmlns:ns="urn:crmondemand/ws/customobject2/10/2004" xmlns:p0="urn:crmondemand/ws/customobject2/10/2004" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CustomObject2Id>AAGA-3G95ON</CustomObject2Id>
<Name>123 Street Blvd</Name>
- <ListOfContact>
- <Contact>
<ContactId>AAGA-3G1NHA</ContactId>
</Contact>
</ListOfContact>
</CustomObject2>
I have following XSLT for merging these XML into one XML record.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="exslt saxon bpws cis ihmap p1 p0 cou0 cou1 cobject0 cobject1" version="2.0"
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:cis="http://www.approuter.com/schemas/2003/1/UserCallouts/"
xmlns:exslt="http://exslt.org/common" xmlns:ihmap="http://www.approuter.com/xmlns/2002/Mapping"
xmlns:p0="urn:/crmondemand/xml/Contact/Data" xmlns:p1="urn:crmondemand/ws/ecbs/contact/10/2004"
xmlns:saxon="http://saxon.sf.net/" xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cou0="urn:/crmondemand/xml/User/Data" xmlns:cou1="urn:crmondemand/ws/ecbs/user/10/2004"
xmlns:cobject0="urn:crmondemand/ws/customobject2/10/2004" xmlns:cobject1="urn:/crmondemand/xml/customobject2">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:variable name="srcDoc1" select="/"/>
<xsl:variable name="CRMODUserOutPut" select="document(User.xml)"/>
<xsl:variable name="CRMODCobjectOutPut" select="document(AddressCO.xml)"/>
<xsl:template match="/">
<xsl:element name="Contact" namespace="">
<xsl:for-each select="$srcDoc1/p0:Contact">
<xsl:variable name="AccountModifiedId" select="p0:stModified_By_User_ID"/>
<xsl:variable name="ContactIdCO" select="p0:Id"/>
<xsl:if test="string-length(p0:Id)>0">
<xsl:element name="contactid" namespace="">
<xsl:value-of select="p0:Id"/>
</xsl:element>
<xsl:element name="primaryaccountid" namespace="">
<xsl:value-of select="p0:AccountId"/>
</xsl:element>
<xsl:element name="primaryaddressid" namespace="">
<xsl:value-of select="p0:CustomObject2Id"/>
</xsl:element> 
<xsl:element name="salesrep" namespace="">
<xsl:value-of select=" $CRMODUserOutPut/cou1:UserQueryPage_Output/cou0:ListOfUser/cou0:User[cou0:Id=$AccountModifiedId]/cou0:ExternalSystemId"/>
</xsl:element> 
<xsl:element name="AddressIds" namespace="">
<xsl:value-of select="I need AddressCO CustomObject2Id"/>
</xsl:element>
<xsl:element name="AccountIds" namespace="">
<xsl:value-of select="p0:AccountId"/>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

I am not able to lookup CustomObject2Id from Address so i am confused its like Going down in the tree and getting upper node how can i achieve this? I have stored these XML into my local machine thats why you see document(user.xml) document(addressco.xml).

Thanks in advance
 
Old June 22nd, 2009, 04:45 PM
Authorized User
 
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

I found the solution thanks...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple input xml / get data from other xml file elayaraja.s XSLT 3 July 25th, 2008 06:59 AM
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
XML Merge... babloo81 XML 3 November 14th, 2003 06:44 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.