[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: Re: [xsl] Generating XML fragment to DOM node using XSL


Subject: RE: Re: [xsl] Generating XML fragment to DOM node using XSL
From: cknell@xxxxxxxxxx
Date: Tue, 16 Dec 2003 15:49:44 -0500

Here are two XML documents and an XSLT stylesheet

sduss_a.xml
-------------
<?xml version="1.0" encoding="UTF-8" ?>
<menu>
  <breakfast />
  <lunch />
</menu>


sduss_b.xml
-------------
<?xml version="1.0" encoding="UTF-8" ?>
<dinner>
  <salad />
  <soup />
  <main-dish />
  <dessert />
</dinner>

sduss.xsl
-------------
<?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:variable name="dinner" select="document('sduss_b.xml')" />

  <xsl:template match="/menu">
    <menu>
      <xsl:copy-of select="*" />
      <xsl:copy-of select="$dinner/*" />
    </menu>
  </xsl:template>

</xsl:stylesheet>

Now apply suss.xsl to sduss_a.xml and you will get:

<?xml version="1.0" encoding="UTF-8"?>
<menu>
<breakfast />
<lunch />
<dinner>
  <salad />
  <soup />
  <main-dish />
  <dessert />
</dinner>
</menu>

There it is, processed with XALAN-J. I'm still new to Java, so I won't be able to help you debug your program, but the problem is clearly not XSL and you may do better posting to the XALAN-J list to get pointers programming those classes.
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Steve Dussinger <sdussing@xxxxxxxxx>
Sent:     Tue, 16 Dec 2003 12:00:01 -0800
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Re: [xsl] Generating XML fragment to DOM node using XSL

On 12/16/03 11:37 AM, "cknell@xxxxxxxxxx" <cknell@xxxxxxxxxx> wrote:

> You didn't give us much information, but if I had to guess, I would say that
> you are somehow appending one document to another. Consequently, there is no
> single, encompassing root element. There are two at the top level, the root
> node of the first document and the root node of the second document are
> siblings with no parent. That would surely produce the complaint you describe.
> 
> You will have to put make the root node of one document a descendent of the
> root node of the other.

That's what I'm currently doing. Let me describe a little more detail
here...

I have a current DOM document with the following structure:

    ui
    |
    ---listbox
       |
       ---model

My XSLT stylesheet takes nodes from the source DOM tree with the following:

    addrList
    |
    ---address (this node and descendants repeats n times).
       |
       ---name

So what I want to do is in my XSL, grab all of the nodes from source tree
named 'name' and place them as children of the destination node 'model'.

The resulting tree should look like this:

    ui
    |
    ---listbox
       |
       ---model
          |
          ---name
          |
          ---name
          |
          ---name

Etc.

My XSL seems to work, in that it finds the correct nodes in the source
document, but when it tries to place them as children of the model node, it
fails with the error I mentioned before.

If I change my XSL stylesheet to create a dummy node, and then place all of
the names under that, then place the dummy node under 'model', it works.

I've setup my call to Xalan to use a DOMSource and a DOMResult, with the
appropriate nodes from the DOM trees selected. I can look at the DOMSource
and DOMResult in the Java debugger, so I know I'm looking at the right
nodes. Yet still Xalan balks...

--Steve


 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
Keywords