Search code examples
javaxslttransformer-model

TransformerConfigurationException: Could not compile stylesheet, error - no protocol


I have an XMl which I trying to convert using transformer.

I am getting the following error:

ERROR:  'no protocol:
FATAL ERROR:  'Could not compile stylesheet'
javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at    com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:885)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:671)

My code which performs this transform is:

Source xslInput = new StreamSource(finalStr);
        Source xmlInput = new StreamSource(str);

        Transformer transformer = factory.newTransformer(xslInput);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Result result = new StreamResult(bos);
        transformer.transform(xmlInput, result);
        String s = new String(bos.toByteArray());

The XLS file which I am using is located at the following location: https://code.google.com/p/ccd-bluebutton/source/browse/trunk/Bluebutton/ccd/xslt/CCDtoBlueButtonTxt_Resource.xsl?r=103

Can you please tell where I am going wrong?

Regards, Radhika


Solution

  • Take a look here.

    The solution provided consists on creating a StreamSource from a path, so you have:

    File xslInput = new File("path/to/file");
    TransformerFactory transformer = TransformerFactory.newInstance();
    Templates xsl = transformer.newTemplates(new StreamSource(xlsInput));
    

    Hope it helps.