The following comment has been added to this issue:
Author: Joe Kesselman
Created: Mon, 20 Sep 2004 6:17 AM
Body:
Note that DOMResult normally builds to a Document node, and the DOM enforces the
restriction that a Document may have only one root Element.
To build a document fragment/external-entity with multiple top-level elements, the DOM
insists that you use a DocumentFragment node as the root -- or that you contruct this
under a dummy top-level element and ignore/discard that later.
I know we intended to support DocumentFragment through DOMResult -- though the user
would have to explicitly request that thru the API rather than our trying to recognize
non-XML-Document output and change it on the fly. I'm not sure whether that was ever
implemented or not.
---------------------------------------------------------------------
View this comment:
http://issues.apache.org/jira/browse/XALANJ-1752?page=comments#action_53236
---------------------------------------------------------------------
View the issue:
http://issues.apache.org/jira/browse/XALANJ-1752
Here is an overview of the issue:
---------------------------------------------------------------------
Key: XALANJ-1752
Summary: DOMResult(Node) fails for Element when transform outputs more than one
root node.
Type: Bug
Status: Unassigned
Priority: Blocker
Project: XalanJ2
Components:
DOM
Versions:
2.5
Assignee:
Reporter: Josh Canfield
Created: Thu, 18 Dec 2003 1:23 AM
Updated: Mon, 20 Sep 2004 6:17 AM
Environment: Operating System: All
Platform: All
Description:
When using a DOMResult with an Element as the parameter a SAXException (Can't
have more than one root on a DOM!) when the template evaluates to more than a
single first level node. The following code/xml/xsl demonstrates the problem.
### test.java
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.*;
import org.w3c.dom.*;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xml.serializer.*;
public class test {
static public void main(String[] args) {
try {
// Create xsl source
StreamSource xslSource = new StreamSource(new File(args
[0]));
// Create xml source
StreamSource xmlSource = new StreamSource(new File(args
[1]));
// Create transformer
TransformerFactory tFactory =
TransformerFactory.newInstance();
/// output the xslt
Transformer transformer = tFactory.newTransformer
(xslSource);
// Create document
// <ui><listbox><model/></listbox></ui>
Document doc = new DocumentImpl();
Element ui = doc.createElement("ui");
Element listbox = doc.createElement("listbox");
Element model = doc.createElement("model");
doc.appendChild(ui);
ui.appendChild(listbox);
listbox.appendChild(model);
DOMResult dr = new DOMResult(model);
transformer.transform(xmlSource, dr);
// Dump to System.out
Transformer identity = tFactory.newTransformer();
identity.setOutputProperty("indent","yes");
identity.setOutputProperty("{http://xml.apache.org/xslt}
indent-amount","4");
identity.transform(new DOMSource(doc), new StreamResult
(System.out));
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
### xml.xml
<?xml version="1.0" encoding="UTF-8"?>
<addrList>
<address>
<name>One</name>
<name>Two</name>
<name>Three</name>
<name>Four</name>
</address>
</addrList>
### xsl.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="no"/>
<xsl:template match="/">
<xsl:copy-of select="addrList/address/name"/>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]