[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Merging two xml files using a template file.

Subject: RE: Merging two xml files using a template file.
From: "Bhaskar Reddy" <bhaskar_reddy@xxxxxxxxxxx>
Date: Mon, 12 Jan 2004 22:49:07 +0530
bhaskar reddy
Hi,

I am just trying to make one xsl file. But it fails at
line :    <xsl:copy-of select="$local/$elemName"/>

It says TestNode expected here....

Can't I combine two variables ???

Thanks
Bhaskar




<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<!-- load the merge file -->
<xsl:variable name="file1" select="document('file1.xml')"/>
<xsl:variable name="file2" select="document('file2.xml')"/>


       <xsl:template match="/">
	     <xsl:call-template name="copyNode"/>
	</xsl:template>

<xsl:template name="copyNode">

		<xsl:for-each select="child::*">
			<xsl:variable name="elemName" select="name()"/>
			<xsl:choose>
				<xsl:when test="@src='file1'">
				      Inside local
				     <xsl:copy-of select="$file1/$elemName"/>
			       </xsl:when>
			       <xsl:when test="@src='file2'">
			             Inside Restored
			            <xsl:copy-of select="$file2/$elemName"/>
			       </xsl:when>
			       <xsl:otherwise>
			           Inside otherwise
			            <xsl:element name="{$elemName}">
			            </xsl:element>
			        </xsl:otherwise>
		      </xsl:choose>
		</xsl:for-each>
	</xsl:template>

</xsl:stylesheet>



From: "SHEIKH Sajjad" <Sajjad.SHEIKH@xxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE:  Merging two xml files using a template file.
Date: Mon, 12 Jan 2004 17:46:28 +0100

Hi there,

Have a look at the document() function in xslt.
You can bring all your files together and then could apply the templates
and operations as you want.

Hope this helps.
/s

-----Original Message-----
From: Bhaskar Reddy [mailto:bhaskar_reddy@xxxxxxxxxxx]
Sent: 12 January 2004 17:32
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Merging two xml files using a template file.


Hi, I have many sets of data in xml files. Each set has three xml files. And

each set has different tree structure. So I am looking for some general
solution.

I want to merge file 1 and file 2, depending on the attribute"src" from
file
3( template file) of the set.

Sample files for a set are as shown below..

the "src" attribute tells from where to get the value of that element.

file 1: xml
-------------
<Data>
     <Name> Peter Radke </Name>
     <Age> 34 </Age>
     <Address>
                <Street> 34 Peter Ave </Street>
                <City> Chicago</City>
                <Country> USA </Country>
     </Address>
</Data>

file 2: xml : Has very similar structure but different values

<Data>
     <Name> Peter </Name>
     <Age> 38 </Age>
     <Address>
                <Street> 38 Bradway st</Street>
                <City> NewYork</City>
                <Country> USA </Country>
     </Address>
</Data>

file 3: xml :
<Data>
     <Name src="file1"> </Name>
     <Age src="file2"></Age>
     <Address src="file2">
     </Address>
</Data>

file 3 is a template file for merging file 1 and file 2.  the src
attribute
in this file tells from where to get the element value from.  For
example
the Name element value should be read from the file1 and the Age should
be
from the file 2. And the whole <Address> structure should be read from
the
file 2.

So the result should look like

Result FILE:
----------------
<Data>
     <Name> Peter Radke </Name>
     <Age> 38 </Age>
     <Address>
                <Street> 38 Bradway st</Street>
                <City> NewYork</City>
                <Country> USA </Country>
     </Address>
</Data>

The structure of these xml files are not predefined. So I can't hard
code
any element names.
Can any one help me how to do it using XSLT.

Thanks
Bhaskar

_________________________________________________________________
Free transactions in any ATM across India.
http://server1.msn.co.in/msnleads/suvidha/dec03.asp?type=hottag Click
here.


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



______________________________________________________________ This message has been scanned for all viruses by BTnet VirusScreen. The service is delivered in partnership with MessageLabs.

This service does not scan any password protected or encrypted
attachments.

If you are interested in finding out more about the service, please
visit our website at
http://www.btignite.com/internetservices/btnet/products_virusscreen.htm
==============================================================

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


_________________________________________________________________
Contact brides & grooms FREE! http://www.shaadi.com/ptnr.php?ptnr=hmltag Only on www.shaadi.com. Register now!



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.