xsl-list
[Top] [All Lists]

RE: RE: Combining two XML files into one

2005-07-20 13:46:04
I was using the first stylesheet to transform kkoch3b.xml. I needed to get 
access to kkoch3a.xml as well. By using the document() function, I could get 
access to a document that was not involved in the transform. The command line 
for the first stylesheet is:

java -jar c:\saxon\saxon.jar kkoch3b.xml kkoch3.xslt

As you can see, there is no reference to kkoch3a.xml on the command line (nor, 
so far as I can tell, can there be), so I had to retrieve it using the 
document() function.

The interesting part (to me) of the second stylesheet is that it doesn't matter 
what XML file you pass to the stylesheet on the command line. It is ignored by 
the stylesheet. All the processing is directed to the two XML files whose names 
are passed as parameters to the two instances of the document() function.


-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



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

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>
--~--




--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>