Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 14th, 2003, 01:22 PM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Merge XML files into a xml file using xslt

I have over 20 xml schema files and want to generate a xml file. I have to use xslt. Any suggestion?

Thanks in advance.

LX

Reply With Quote
  #2 (permalink)  
Old October 17th, 2003, 09:56 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

What do you mean?
You want to merger the 20 files to one large schema or create an xml that satisfies all the schemas?

Joe (MVP - xml)
Reply With Quote
  #3 (permalink)  
Old November 3rd, 2003, 10:53 AM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the response. I have solved the problem.

I am looking for the solution or idea of coverting flat files into a xml file. Using Java programming would be easier for me. But my boss wants me to use xslt. I have converted each flat files into a .xml file. What is the better way for the next step?

Thanks again,

LX

Reply With Quote
  #4 (permalink)  
Old November 3rd, 2003, 11:16 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you want to convert a number of separate xml documents into one then you need to create a new master document and have each old document as a child. The easiest way I can think of is to create a config file such as this with a list of all the documents you need merging:
Code:
<mergeData newRoot="newRoot">
††<fileList>
    <fileItem>myFile1.xml</fileItem>
    <fileItem>myFile2.xml</fileItem>
    <fileItem>myFile3.xml</fileItem>
††</fileList>
</mergeData>
With msxml you can use a path relative to the stylesheet but with some processors you may need the full url, file:///c:/myFolder/myFile.xml for example.
Your stylesheet looks like:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
††<xsl:template match="/">
    <xsl:element name="{mergeData/@newRoot}">
    ††<xsl:apply-templates select="mergeData/fileList/fileItem"/>
    </xsl:element>
††</xsl:template>
††<xsl:template match="fileItem">    
    <xsl:copy-of select="document(.)"/>
††</xsl:template>
</xsl:stylesheet>
Replace the newRoot attribute value with your choice of new document element.

This simple merger won't work with source xml files that have embedded DTDs but given that you created these files from flat files this seems unlikely.

Joe (MVP - xml)
Reply With Quote
  #5 (permalink)  
Old November 6th, 2003, 06:01 PM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT between two XML files NEO1976 XSLT 15 July 24th, 2006 09:52 AM
Problem to create an xml file from two xml files saurabh_inblore XSLT 1 April 12th, 2006 03:58 AM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 09:48 AM
Merge two Similar XML files myunus XML 5 August 5th, 2004 12:12 AM
Merge xml schema files mayada XSLT 0 April 16th, 2004 11:37 AM



All times are GMT -4. The time now is 05:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.