[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
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
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.
<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: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
[xsl] Merge two XML files
Subject: [xsl] Merge two XML files From: "Kim Tran" <tav1210@xxxxxxxxxxx> Date: Tue, 29 Apr 2003 18:01:48 -0700 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] find previous node at the, Jarno . Elovirta | Thread | Re: [xsl] Merge two XML files, Rob Rohan |
[xsl] find previous node at the sam, Mark Ivs | Date | Re: [xsl] Merge two XML files, Rob Rohan |
Month |