xsl-list
[Top] [All Lists]

RE: Combining two XML files into one

2005-07-20 13:16:52
Thank you for the quick response and fixing my mistakes. Why did you only
use kkoch3a in the first stylesheet? 

Actually I do not need sorting, but thank you for providing it anyway.

Thank you very much - I am testing it right now,
Karl


--- Ursprüngliche Nachricht ---
Von: cknell(_at_)onebox(_dot_)com
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: RE: [xsl] Combining two XML files into one
Datum: Wed, 20 Jul 2005 16:09:10 -0400

After fixing the xml, the solution is to use the document() function. The
bookshelf elements had two opening tags and no closing tag, and the book
elements had nothing resembling a closing tag. 

I saved one file as kkoch3a.xml and the other as kkoch3b.xml. The first
stylesheet works if the books are in sorted order already. The second
style
sheet sorts them if that is what you want and they are not already in the
sort order you wish to have.

-- no sorting --
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes" encoding="UTF-8" />
  <xsl:strip-space elements="*" />
  <xsl:variable name="kkoch3a" select="document('kkoch3a.xml')" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="bookshelf">
    <bookshelf>
      <xsl:apply-templates select="$kkoch3a/bookshelf/book" />
      <xsl:apply-templates />
    </bookshelf>
  </xsl:template>

  <xsl:template match="book">
    <xsl:copy-of select="." />
  </xsl:template>

</xsl:stylesheet>

-- sorting --
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes" encoding="UTF-8" />
  <xsl:strip-space elements="*" />
  <xsl:variable name="kkoch3a" select="document('kkoch3a.xml')" />
  <xsl:variable name="kkoch3b" select="document('kkoch3b.xml')" />

  <xsl:template match="/">
    <xsl:call-template name="sort-books" />
  </xsl:template>

  <xsl:template name="sort-books">
    <bookshelf>
      <xsl:for-each select="$kkoch3a/bookshelf/book |
$kkoch3b/bookshelf/book">
        <xsl:sort select="title" />
        <xsl:apply-templates select="." />
      </xsl:for-each>
    </bookshelf>
  </xsl:template>

  <xsl:template match="book">
    <xsl:copy-of select="." />
  </xsl:template>

</xsl:stylesheet>
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Karl Koch <TheRanger(_at_)gmx(_dot_)net>
Sent:     Wed, 20 Jul 2005 21:29:02 +0200 (MEST)
To:       "Mulberry list" <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  [xsl] Combining two XML files into one

Hello all,

how can I combine two XML files into one assuming that I have the same
structre in both files like this:

(The first file)

<bookshelf>
  <book><title>1st Book</title>
  <book><title>2nd Book</title>
  <book><title>3rd Book</title>
<bookshelf>
 
(The second file)

<bookshelf>
  <book><title>4th Book</title>
  <book><title>5th Book</title>
  <book><title>6th Book</title>
<bookshelf>


I wouild like to have the following file:

<bookshelf>
  <book><title>1st Book</title>
  <book><title>2nd Book</title>
  <book><title>3rd Book</title>
  <book><title>4th Book</title>
  <book><title>5th Book</title>
  <book><title>6th Book</title>
<bookshelf>

Is this possible? If yes, how can I do that? I am using SAXON. 

Kind Regards,
Karl

-- 
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse fo?=r Mail, Message, More +++

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


-- 
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse f�r Mail, Message, More +++

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--