XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 26th, 2011, 06:32 PM
anhedonia anhedonia is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 2 anhedonia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old January 27th, 2011, 01:40 AM
xml-profi xml-profi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 190 xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 8 m 25 sec
Reputation Power: 48
Send a message via ICQ to xml-profi
When you use browser the browser display
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="xml"/>
	<xsl:template match="/">
		<root>
			<xsl:apply-templates select="book"/>
		</root>
	</xsl:template>
	<xsl:template match="book">
		<xsl:apply-templates select="metadata"/>
		<xsl:apply-templates select="content"/>
	</xsl:template>
	<xsl:template match="metadata">
		<metadata>
			<title>
				<xsl:value-of select="title"/>
			</title>
			<auther>
				<xsl:value-of select="author"/>
			</auther>
			<xsl:variable name="data" select="document('metadatasource.xml')/metadata"/>
			<page>
				<xsl:value-of select="$data/pages"/>
			</page>
			<publishdate>
				<xsl:value-of select="$data/publishdate"/>
			</publishdate>
		</metadata>
	</xsl:template>
	<xsl:template match="content">
		<content>
			<xsl:apply-templates select="page"/>
		</content>
	</xsl:template>
	<xsl:template match="page">
		<page>
			<xsl:value-of select="."/>
		</page>
	</xsl:template>
</xsl:stylesheet>


this

Code:
<?xml version='1.0' ?>
<root>
  <metadata>
    <title>Tom Sawyer</title>
    <auther>Mark Twain</auther>
    <page>300</page>
    <publishdate>1900</publishdate>
  </metadata>
  <content>
    <page>1</page>
    <page>2</page>
    <page>3</page>
  </content>
</root>


but you a parser
then

parser xsl-file xml-file output-file

output-file is same name as xml file
__________________
Helmut Hagemann Germany

fallen to the bottom of the facts?
I reach my hand and we go together


wer lesen und google kann ist klar im Vorteil
who read and google is able is clear in the advantage

Reply With Quote
  #3  
Old January 27th, 2011, 12:41 PM
anhedonia anhedonia is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 2 anhedonia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 2 sec
Reputation Power: 0
edit: removed

Reply With Quote
  #4  
Old January 28th, 2011, 02:42 AM
xml-profi xml-profi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 190 xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 8 m 25 sec
Reputation Power: 48
Send a message via ICQ to xml-profi
can you display booksource.xml
is diffclut or ritle
where are the attributes

Code:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<book>
	<metadata>
		<title>Tom Sawyer</title>
		<author>Mark Twain</author>
	</metadata>
	<content attr1="attr1" href="attr2">
		<item attr1="attr1" href="attr2"></item>
		<page>1</page>
		<page>2</page>
		<page>3</page>
	</content>
</book>

Reply With Quote
  #5  
Old April 7th, 2011, 09:34 AM
seolawkumar seolawkumar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 3 seolawkumar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 21 m 38 sec
Reputation Power: 0
xml

Okay? can you display booksource.xml

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Insert data from one XML file into another, existing XML document with XSLT

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap