0

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.

Community
  • 1
  • 1
TheBakker
  • 2,852
  • 2
  • 28
  • 49
  • When you use a StringWriter, how do you examine the result? Try printing the value of `writer.toString().contains("Disponibilit\u00e9")`. Also, when you view the original file in Vim, what does `:set fileencoding` show? – VGR Feb 02 '17 at 18:03
  • Sorry I'd to run after my message. So I'd checked the writer content but it doesnt really contains the content being generated. For the encoduing VIM shows it's always `UTF-8`, no matter if I try to use set encoding to something else through `setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");` – TheBakker Feb 03 '17 at 10:13
  • I just checked the encoding of my `.xsl` & `.xml` files with vim as well, and even though the header of both files is `` the `.xml` file shows an `UTF-8` enconding and the `.xsl` file a `latin1` encoding ... – TheBakker Feb 03 '17 at 10:31
  • That seems to be the issue, then. I believe in Vim, you can do `:set fileencoding=iso-8859-1` and then save the file, to force it to be saved in the right encoding. – VGR Feb 03 '17 at 14:33

0 Answers0