[ACCEPTED]-Java Transformer error: Could not compile stylesheet-xslt
Accepted answer
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();
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());
System.out.println(s);
To use XSLTC, put xalan.jar(2.5), serializer.jar, xml-apis.jar, and 1 xercesImpl.jar on your classpath .
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.