David --
The results that you're getting just don't seem consistent with that I'm
seeing. I repeat that the most likely cause of this is that your
stylesheet is creating multiple top-level Nodes which is not allowed in
the DOM model. You can have a maximum of one Element, a maximum of one
Document Type, and any number of Processing Instructions or Comments and
no other children of the Document (including text nodes). The problem
is with your stylesheet, not your input DOM.
You say that this is happening with any xslSource that you use but that
just doesn't make sense to me at the moment. I created the following
program and it works fine:
import java.io.File;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.apache.xerces.dom.DOMImplementationImpl;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.templates.OutputProperties;
public class Quickie19 {
public static void main(String[] argv) throws Exception {
String xslFile = "c:\\Program
Files\\xalan-j_2_2_D6\\samples\\Pipe\\foo1.xsl";
DOMImplementation dom = new DOMImplementationImpl();
Document xml = dom.createDocument(null, "doc", null);
Source xslSource = new StreamSource(new File(xslFile));
Source xmlSource = new DOMSource(xml);
DOMResult xsltOut = new DOMResult();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xslSource);
transformer.transform(xmlSource, xsltOut);
Serializer serializer = SerializerFactory.getSerializer
(OutputProperties.getDefaultMethodProperties("xml"));
serializer.setOutputStream(System.out);
serializer.asDOMSerializer().serialize(xsltOut.getNode());
}
}
Also, please note that nodes not in a namespace in the DOM model should
use the value "null" for the namespace rather than an empty string, but
I don't think this is your problem.
Also, please do not send HTML to the list. It makes it difficult to
respond to for some of us.
Please supply a copy of the stylesheet that you're actually using
together with the StreamResult output and we'll have a look.
Gary
--------------------------------------------------------------------------------
Before I was just constructing the input Document with a DocumentImpl()
constructor. I switched to:
DOMImplementation dom = new DOMImplementationImpl();
Document xml = dom.createDocument("", "Test", null);
I still get the same error. I tried changing all createElement and
setAttribute commands to their equivalent NS commands with a ""
namespace and still got the same
error. Below is how I invoke Xalan. xml is a DOM that I have in
memory, xslFile is a path to a file. If I use a StreamResult everything
works fine.
Source xslSource = new StreamSource(new File(xslFile));
Source xmlSource = new DOMSource(xml);
DOMResult xsltOut = new DOMResult();
Transformer transformer = factory.newTransformer(xslSource);
transformer.transform(xmlSource, xsltOut);
Thanks for your help,
Dave Frankson