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

Re: mixing two XMLs

Subject: Re: mixing two XMLs
From: "Anthony B. Coates" <abcoates@xxxxxxxxxxxxx>
Date: Fri, 8 Nov 2002 11:56:52 GMT
add two xmls xslt
** Reply to message from "Felix Garcia" <fnmtool@xxxxxxxxxxx> on Fri, 08 Nov
2002 11:37:46 +0000

Dear Felix,

> I have two XML and I want to mix them depending on a element value , like 
> two tables with a relation in a relational database

I would suggest

* Use the first file, with the book information, as the input to your XSLT.
* Start with an identify transformation that copies everything.
* Create a template for <book> that copies its content, then use the
"document()" function to add the page information.

So, the <book> template would look like (and I haven't tested this)

	<xsl:template match = "book">
		<xsl:copy>
			<xsl:apply-templates/> <!-- assumes you have default "copy everything"
templates set up -->
			<xsl:variable name = "bookId" select = "id_book"/>
			<xsl:apply-templates select = "document('pages.xml')/pages/page[id_book =
$bookId]>
		</xsl:copy>
	</xsl:template>

You also need to remove the page's book ID, so you also need

	<xsl:template match = "page/id_book"/>

so suppress it.  Hope that helps.  With big documents, you might want to use an
XSLT key to index pages by their book ID, but that's just an extra.

	Cheers,
		Tony.

> My XMLs are:
> 
> <books>
> 	<book>
> 		<id_book>2</idbook>
> 		<tittle>title1</tittle>
> 		<Edition>2000</Edition>
> 		<chapters>
> 			<number>12</number>
> 		</chapters>
> 	</book>
> 	<book>
> 		<id_book>7</idbook>
> 		<tittle>title2</tittle>
> 		<Edition>2001</Edition>
> 		<chapters>
> 			<number>19</number>
> 		</chapters>
> 	</book>
> 	<book>
> 		<id_book>9</idbook>
> 		<tittle>title3</tittle>
> 		<Edition>2001</Edition>
> 		<chapters>
> 			<number>9</number>
> 		</chapters>
> 	</book>
> </books>
> 
> <pages>
> 	<page>
> 		<id_book>2</id_book>
> 		<n_page>765</n_page>
> 		<topic_data>
> 			<ocurrences>34</ocurrences>
> 			<value>tree</value>
> 		</topic_data>
> 	</page>
> 	<page>
> 		<id_book>9</id_book>
> 		<n_page>1023</n_page>
> 		<topic_data>
> 			<ocurrences>21</ocurrences>
> 			<value>bird</value>
> 		</topic_data>
> 	</page>
> <pages>
> 
> And I want to generate next xml.The element used as 'key' is id_book:
> 
> <books>
> 	<book>
> 		<id_book>2</idbook>
> 		<tittle>title1</tittle>
> 		<Edition>2000</Edition>
> 		<chapters>
> 			<number>12</number>
> 		</chapters>
> 		<page>
> 			<n_page>765</n_page>
> 			<topic_data>
> 				<ocurrences>34</ocurrences>
> 				<value>tree</value>
> 			</topic_data>
> 		</page>
> 	</book>
> 	<book>
> 		<id_book>7</idbook>
> 		<tittle>title2</tittle>
> 		<Edition>2001</Edition>
> 		<chapters>
> 			<number>19</number>
> 		</chapters>
> 	</book>
> 	<book>
> 		<id_book>9</idbook>
> 		<tittle>title3</tittle>
> 		<Edition>2001</Edition>
> 		<chapters>
> 			<number>24</number>
> 		</chapters>
> 		<page>
> 			<n_page>1023</n_page>
> 			<topic_data>
> 				<ocurrences>21</ocurrences>
> 				<value>bird</value>
> 			</topic_data>
> 		</page>
> 	</book>
> </books>
====
Anthony B. Coates, Information & Software Architect
mailto:abcoates@xxxxxxxxxxxxx
MDDL Editor (Market Data Definition Language)
http://www.mddl.org/

 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.