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