I'm generating a CSV file from a XSL and XML files.
Both original files have <?xml version="1.0" encoding="ISO-8859-1"?>
as header.
String csvPath = "myCsvPath";
String xmlPath = "xmlPath.xml";
String xslPath = "xslPath.xsl"
File xmlFile = new File(xmlPath);
File xslFile = new File(xslPath);
Source xmlSource = new StreamSource(xmlFile);
Source xslSource = new StreamSource(xslFile);
Result result = new StreamResult(new ByteArrayOutputStream());
TransformerFactory transFac = new TransformerFactoryImpl();
Transformer trans = transFac.newTransformer(xslSource);
trans.setParameter("CSV_PATH","file:///" + csvPath);
trans.transform(xmlSource,result);
I'm using net.sf.saxon.Controller as Transformer. The version of Saxon is 9.1.0.8 but I also tried with 9.4 without any luck. In my XSL file one of the label is "Disponibilité"
If I launch the generation on my Dev tomcat which is on windows, the CSV header is "Disponibilité", no problem.
However if I launch the generation on a linux VM, the "é" is not encoded correctly : "Disponibilit�
"
I've checked with vim and log, the original file shows "é" correctly.
But once the generation is done, if I parse the first line of my file through vim or log I see the é
is changed to □
I checked similar question like : transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8") is NOT working
But setting trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
is not working.
Nor does using StringWriter instead of ByteArrayOutputStream.