|
Subject: Re: [xsl] mixing two XMLs From: "Anthony B. Coates" <abcoates@xxxxxxxxxxxxx> Date: Fri, 8 Nov 2002 11:56:52 GMT |
** 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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] mixing two XMLs, Felix Garcia | Thread | RE: [xsl] mixing two XMLs, Américo Albuquerque |
| [xsl] mixing two XMLs, Felix Garcia | Date | RE: [xsl] mixing two XMLs, Jarno . Elovirta |
| Month |