ASP Error: 70
Description: Permission denied
Source: Microsoft VBScript runtime error

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

Merge two XML files

Subject: Merge two XML files
From: "Kim Tran" <tav1210@xxxxxxxxxxx>
Date: Tue, 29 Apr 2003 18:01:48 -0700
merge two xml document
I have 2 XML files that I want to be able to merge them together given a list of keys. I have searched the group but the examples are slightly different than ours. Our XML files have the following format:
XML1.xml


<Document>
 <row>
   <column name="FirstName">Smith</column>
   <column name="LastName">John</column>
   <column name="Address">7777 First </column>
 </row>
 <row>
   <column name="FirstName">Smith2</column>
   <column name="LastName">John2</column>
   <column name="Address">7777 Second </column>
 </row>
...
</Document>

XML2.xml
<Document>
 <row>
   <column name="FirstName">Smith</column>
   <column name="LastName">John</column>
   <column name="Age">36</column>
 </row>
 <row>
   <column name="FirstName">Smith2</column>
   <column name="LastName">John2</column>
   <column name="Age">40</column>
 </row>
...
</Document>

The result XML should be:
<Document>
 <row>
   <column name="FirstName">Smith</column>
   <column name="LastName">John</column>
   <column name="Address">7777 First </column>
   <column name="Age">36</column>
 </row>
 <row>
   <column name="FirstName">Smith2</column>
   <column name="LastName">John2</column>
   <column name="Address">7777 Second </column>
   <column name="Age">40</column>
 </row>
...
</Document>

Here is my first attempt of writing the XSL file. For simplification, I just tried to merge them based on the "FirstName" column. However, I don't know how to specify the key to search in the second file.


<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xalan">

<xsl:output method="xml" indent="yes"/>

<xsl:param name="source" select="c:/temp/kmtable2.xml"/> <!--source of data-->

<xsl:key name="row" match="$source/Document/row" use="column[@name='FirstName']"/>

<xsl:template match="/">        <!--document element-->
  <Document>
     <xsl:for-each select="Document/row">
       <xsl:copy-of select="."/>
       <xsl:variable name="name" select="column[@name='FirstName']"/>
       <xsl:for-each select="document($source)/Document/row">
         <xsl:apply-templates select="key('row', $name)"/>
       </xsl:for-each> -->
     </xsl:for-each>
  </Document>
</xsl:template>

<xsl:template match="row">
 <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

It kept complaining about "A node test that matches either NCName:* or QName was expected.". It looks like it doesn't like the match claus in <xsl:key>.


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



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.