|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Merging two documents
Do you think using document() is superior to
concatenating the two documents first?
For example, the following XML document
would be created:
<ConcatenatedDocument>
<DocumentA>
<Book id="1"><Name>The wizard of OZ</Name></Book>
<Book id="2"><Name>Java Servlet Programming</Name></Book>
<Book id="3"><Name>John Coltrane Rage</Name></Book>
</DocumentA>
<DocumentB>
<BookList>
<Book id="1"/>
<Book id="2"/>
</BookList>
</DocumentB>
</ConcatenatedDocument>
Since my knowledge of XSLT is limited, I don't know if you can
merge this document to the desired form.
----- Original Message -----
From: G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx>
To: XSL List <xsl-list@xxxxxxxxxxxxxxxx>
Sent: Monday, September 13, 1999 8:19 PM
Subject: RE: Merging two documents
> At 99/09/13 19:38 -0700, Earl Bingham wrote:
> >I would be really interested in how this is implemented
> >with examples!
> ...
> >On Behalf Of Terris
> >Sent: Monday, September 13, 1999 6:24 PM
> >To: xsl-list@xxxxxxxxxxxxxxxx
> >Subject: Merging two documents
> >
> >Can I use XSLT to do this?
> >
> >I want to add part of an XML document to another
> >XML document.
>
> A working example using XT-19990813 is below.
>
> I hope this helps.
>
> ........ Ken
>
> p.s. note that your ID attribute values don't match the Name production
> according to XML REC 1.0 Section 3.3.1, but since the instance isn't being
> validated, there is no complaint from the software.
>
> T:\ftemp>type doc1.xml
> <?xml version="1.0"?>
> <!DOCTYPE BookSet [
> <!ATTLIST Book id ID #IMPLIED>
> ]>
> <BookSet>
> <Book id="1"><Name>The wizard of OZ</Name></Book>
> <Book id="2"><Name>Java Servlet Programming</Name></Book>
> <Book id="3"><Name>John Coltrane Rage</Name></Book>
> </BookSet>
>
> T:\ftemp>type doc2.xml
> <BookList>
> <Book id="1"/>
> <Book id="2"/>
> </BookList>
>
> T:\ftemp>type list.xsl
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
>
> <xsl:output method="xml" indent="yes"/>
>
> <xsl:param name="source" select="''"/> <!--source of data-->
>
> <xsl:template match="/BookList"> <!--document element-->
> <BookList>
> <xsl:for-each select="Book">
> <Book id="{@id}">
> <xsl:variable name="id" select="string(@id)"/>
> <!--note you cannot use document($source)/id($id)-->
> <xsl:for-each select="document($source)">
> <xsl:copy-of select="id($id)/*"/>
> </xsl:for-each>
> </Book>
> </xsl:for-each>
> </BookList>
> </xsl:template>
>
> </xsl:stylesheet>
>
> T:\ftemp>xt doc2.xml list.xsl result.xml source=doc1.xml
>
> T:\ftemp>type result.xml
> <BookList>
> <Book id="1">
> <Name>The wizard of OZ</Name>
> </Book>
> <Book id="2">
> <Name>Java Servlet Programming</Name>
> </Book>
> </BookList>
>
> T:\ftemp>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








