XSL transformation give me wrong encoding

2019-09-17 18:10发布

I got a xsl-file that transform a xml-file to another one, with different xml-format. The xsl-file starts with:

        ?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"

And then the output starts with:

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

And the rest of all elements that will be transformed, like alot of lines as:

        <xsl:element name="tns:corporateName" >
          <xsl:value-of select="@CorpOrgname"/>
        </xsl:element>

Everything looks nice, except for that the resulting xml-file has this tag in line 1:

 <?xml version="1.0" encoding="Windows-1252"?

I cannot understand where this encoding comes from. When I debug the file locally the result is utf-8, but not when this application uses it.

Is there anyway to force it more to set it as utf-8? Because that is a demand. The receiving system is some Unix-system.

I have got an example of the original file. That one I will transform, and that is in utf-8 format (during what notepad++ says anyway).

Am I missing something here, is there another way to set the result:s encoding than the syntax encoding="utf-8"?

1条回答
Deceive 欺骗
2楼-- · 2019-09-17 18:40

Look at how the transformation is being run. Perhaps the output is being sent to a DOM tree and is then serialized by the DOM serializer not the XSLT serializer - in this case the encoding requested in the stylesheet will be ignored.

查看更多
登录 后发表回答