Hello list,
I get a javax.xml.tranform.TranformerConfigurationException when creating a new Transformer instance with a stylesheet that is a javax.xml.source.DOMSource object. The stylesheet works fine as a StreamSouce, and when using saxon, a DOMSource. Is this a bug or am I doing something wrong? I attach a short java class that exhibits this behavior. I'm using xalan 2.2-D10. Stack trace is rather long so I won't include it here this time.
thanks, Charles
import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import javax.xml.transform.dom.DOMSource; import java.io.StringReader; import org.xml.sax.InputSource;
public class XalanBug {
private static final String stylesheet =
"<?xml version=\"1.0\"?>\n"+
"<xsl:stylesheet version=\"1.0\""+
" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"+
" <xsl:template match=\"/\">"+
" <xsl:copy-of select=\".\"/>"+
" </xsl:template>"+
"</xsl:stylesheet>";
private static final String document =
"<?xml version=\"1.0\"?>\n"+
"<root>booga</root>";
public static void main(String[] args) {
try {
DocumentBuilderFactory dfact =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder =
dfact.newDocumentBuilder();
DOMSource domStylesheet =
new DOMSource(builder.parse(new InputSource(new
StringReader(stylesheet))),"");
StreamSource streamStylesheet =
new StreamSource(new StringReader(stylesheet),""); //saxon doesn't
like null systemId
TransformerFactory tfact =
TransformerFactory.newInstance();
Transformer streamTrans =
tfact.newTransformer(streamStylesheet); //this works fine
streamTrans.transform(new StreamSource(new StringReader(document)),new
StreamResult(System.out));
Transformer domTrans =
tfact.newTransformer(domStylesheet); //Exeption thrown here
domTrans.transform(new StreamSource(new StringReader(document)),new
StreamResult(System.out));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
