The following comment has been added to this issue:
Author: Alexei Yudichev
Created: Mon, 20 Sep 2004 6:34 AM
Body:
new DOMResult(Element) constructor, according to its JavaDoc, is supposed to allow
any, even non-single-rooted output to be appended to the element node passed (however,
this is not stated implicitly). I can't see the restriction of a single root here. In
contrast, new DOMResult(Document) and new DOMREsult() constructors restrict
transformation output to be a single-rooted tree. Most likely, this is the specs gap
somewhere here. But:
1) looking at xalan's DOMBuilder code, I can clearly see that current node variable is
initialized with the element passed as parameter to new DOMResult(Element), however,
after the first output Element is processed (SIC! DOMBuilder will allow any number of
text nodes before the first element, but will throw an exception when attempting to
output the second Element!), current node is set to null, rather than returning to
previous value.
2) Saxon allows that
3) Allowing to append more than one node to Element sounds quite logical
---------------------------------------------------------------------
View this comment:
http://issues.apache.org/jira/browse/XALANJ-1752?page=comments#action_53237
---------------------------------------------------------------------
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:34 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]