[ACCEPTED]-Java Transformer error: Could not compile stylesheet-xslt

Accepted answer
Score: 10

The constructor

public StreamSource(String systemId)

Construct a StreamSource from a URL. I 3 think you're passing the content of the 2 XSLT instead. Try this:

File xslFile = new File("path/to/your/xslt");
TransformerFactory factory = TransformerFactory.newInstance();
Templates xsl = factory.newTemplates(new StreamSource(xslFile));

You must also set 1 the OutputStream that your StreamResult will write to:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Result result = new StreamResult(baos);
transformer.transform(xmlInput, result);
return baos.toString();
Score: 1

You will have to contruct a stream from 3 the xslt string you have and then use it 2 as the stream source

InputStream xslStream = new ByteArrayInputStream(XSLTRule.getBytes("UTF-8"));
Source xslInput = new StreamSource(xslStream);

To get the result to 1 a string :

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Result result = new StreamResult(bos);
    transformer.transform(xmlInput, result);
    String s = new String(bos.toByteArray());
Score: 0

To use XSLTC, put xalan.jar(2.5), serializer.jar, xml-apis.jar, and 1 xercesImpl.jar on your classpath .

More Related questions