RE: [xsl] mixing two XMLs

Subject: RE: [xsl] mixing two XMLs
From: "Américo Albuquerque" <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Sat, 9 Nov 2002 14:36:17 -0000
Hi Felix.
Try this:
 <!-- select the books -->
 <xsl:template match="books">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates select="book"/>
  </xsl:copy>
 </xsl:template>

 <!-- copy the current book -->
 <xsl:template match="book">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  <!-- process the current's book page -->
  <xsl:apply-templates
select="document('pages.xml')/pages/page[id_book=current()/id_book]">
   <xsl:with-param name="book" select="current()"/>
  </xsl:apply-templates>
  </xsl:copy>
 </xsl:template>

 <!-- copy the book's page, ignoring the extra information -->
 <xsl:template match="page">
  <xsl:param name="book" select="."/>
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates select="*[not(name()=name($book/*))]"/>
  </xsl:copy>
 </xsl:template>

 <!-- identity transform -->
 <xsl:template match="node()">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  </xsl:copy>
 </xsl:template>

Hope that this helps you.


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Felix Garcia
Sent: Friday, November 08, 2002 11:38 AM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] mixing two XMLs


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

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>

How could I do this?

Thanks in advance

_________________________________________________________________
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-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread