1
votes

I'm converting XML to CSV using XSLT. My output line in XSLT is:

<xsl:output method="text" encoding="UTF-8" />

There is a lot of polish letters in XML, that's the problem. When I transform the XML from Notepad++ using XML tools plugin, the output file (not-saved) shows polish letters correctly, and when you click on encoding it shows UTF-8 without BOM. When I save it as CSV - excel doesn't show polish letters. When I change the encoding of file in Notepad++ to UTF-8 with BOM - it works in Excel correctly.

I thought all this is a problem of Notepad++, but when I transform it in XmlSpy the output file is also not correct, like in Excel.

I wonder if I could add the UTF-8 BOM signs at the beggining of the file (from XSLT, not by hand), but all I could find was how to remove them, and I don't even know if that would solve my problem. I'm going crazy with this.

I'm using XSLT 1.0 btw. My encodings in XmlSpy are default, that is UTF-8. Encoding of the input XML is also UTF-8.

1
The problem, such as it is, exists in Excel. If even small projects like Notepad++ can correctly figure out file encodings when opening, it should be embarrassing to Microsoft that they can't implement a functional equivalent in their applications.Eiríkr Útlendi

1 Answers

3
votes

Since you're using XSLT 1.0, you can output &#xFEFF; explicitly...

<xsl:template match="/">
  <xsl:value-of select="'&#xFEFF;'"/>
  <xsl:apply-templates/>
</xsl:template>

If you were using XSLT 2.0, you could just use byte-order-mark="yes" on xsl:output.