You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2003/12/18 02:23:22 UTC
DO NOT REPLY [Bug 25608] New: -
DOMResult(Node) fails for Element when transform outputs more than one root node.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25608>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25608
DOMResult(Node) fails for Element when transform outputs more than one root node.
Summary: DOMResult(Node) fails for Element when transform outputs
more than one root node.
Product: XalanJ2
Version: 2.5
Platform: All
OS/Version: All
Status: NEW
Severity: Normal
Priority: Other
Component: org.apache.xml.utils
AssignedTo: xalan-dev@xml.apache.org
ReportedBy: joshc@plumtree.com
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>