
January 26th, 2011, 06:32 PM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 2
Time spent in forums: 1 h 1 m 2 sec
Reputation Power: 0
|
|
|
Insert data from one XML file into another, existing XML document with XSLT
Hi,
I have two source XML files and I want to take some of the contents of one and insert it into the other.
Source file 1 (metadatasource.xml):
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<metadata>
<pages>300</pages>
<publishdate>1900</publishdate>
</metadata>
My other file is (booksource.xml):
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<book>
<metadata>
<title>Tom Sawyer</title>
<author>Mark Twain</author>
</metadata>
<content>
<page>1</page>
<page>2</page>
<page>3</page>
</content>
</book>
I want to take the content in the <metadata> of metadatasource.xml and add it to the <metadata> of booksource.xml, while maintaining the integrity of the rest of the booksource.xml file (I have edited for brevity sake).
I am able to get the content from metadatsource.xml and dump into a new file, but am unable to add into booksource.xml.
Here is my xsl thus far:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet>
<xsl:template match="/">
<pages><xsl:value-of select="document('metadatasource.xml')/metadata/pages"/></pages>
<publishdate><xsl:value-of select="document('metadatasource.xml')/metadata/publishdate"/></publishdate>
</xsl:template>
</xsl:stylesheet>
thoughts?
thanks
|