Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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 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 October 14th, 2003, 12:22 PM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
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

 
Old October 17th, 2003, 08:56 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old November 3rd, 2003, 10:53 AM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
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

 
Old November 3rd, 2003, 11:16 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old November 6th, 2003, 06:01 PM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.






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





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