Title: RE: Hierarchy error + namespace

Looks like the problem is because the Neko parser is returning
a Document who's elements have a null namespace and the stylesheet
is expecting elements with a html: namespace qualifier. 

Of course I could remove the namespace qualifiers from the
stylesheet but I was wondering if there's another way to
resolve this.  For instance, maybe there's a way to
tell the Neko DomParser to add a namespace qualifier
to the elements ? 

      Nick

-----Original Message-----
From: Simon Kitching [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 21, 2003 7:23 PM
To: Afshartous, Nick
Cc: '[EMAIL PROTECTED]'
Subject: Re: Hierarchy error


Hi Nick,

On Wed, 2003-05-21 at 14:08, Afshartous, Nick wrote:
> I'm running into the Hierarchy error in the following scenario.
> The Neko HTML parser is called and returns a Document object that
> is then passed to Xalan (source attached).
>
> I don't think the error is in the
> stylesheet because I've tried swapping out my stylesheet
> with the birds.xsl in the Xalan distribution with the same result.

Text nodes are not allowed as direct children of a document node (they
must be children of an ELEMENT).

XSL has a "default" rule which goes something like this:

  <xsl:template match="text()">
    <xsl:value-of select="."/>
  </xsl:template>

ie any text node in the input is copied to the output.

The Birds.xsl stylesheet doesn't override this default rule, so applying
the birds.xsl stylesheet to arbitrary input will therefore cause all of
the text nodes in the document to be output. Because none of the other
rules apply, they will be output as direct children of the document
node, causing a HIERARCHY_REQUEST_ERR when the result object (ie the
target of the transform) is a DOM document.

If you run the DOM2DOM birds.xml example with an arbitrary xml document,
then you *will* get the HIERARCHY_REQUEST_ERR for this reason.

The reason this rule is present is that when the result object is a
STREAM, then this rule results in the dumping of all text nodes to the
output, which is quite reasonable.

I suggest that you change your code from using "DOMResult" to using
"StreamResult" as the output of your transform, and checking that what
is displayed is indeed valid xml.

If you still can't see a problem, I suggest you serialise the DOM
returned by Neko (before you try the transform), then post that
document, your stylesheet, and the output generated from your stylesheet
to a StreamResult object to this list.

Hope this helps,

Simon


Reply via email to