Problem:
I’m trying to load a stylesheet in Java but I get an error stateing it isn’t a stylesheet.
The Error:
ERROR: ‘The input document is not a stylesheet (the XSL namespace is not declared in the root element).’
FATAL ERROR: ‘Could not compile stylesheet’
Exception in thread “main” javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:825)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:614)
My Code:
public static void main(String[] args) throws Exception {
String XSLT2 =
"<xsl:stylesheet \n" +
" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" \n" +
" version=\"1.0\"\n" +
" >\n" +
"\n" +
"</xsl:stylesheet>";
String XML = "<foo></foo>";
StreamSource xsltSource = new StreamSource(new StringReader(XSLT2));
Transformer transformer = TransformerFactory.newInstance().newTransformer(xsltSource);
}
It appears that having the Piccolo xml parser in my classpath is causing the problem: http://piccolo.sourceforge.net/.
Not sure exactly what is going on here.
-Dave