Is it possible to change the XML encoding at runtime depending on some condition. Like I want the encoding to be utf-8 if I have set the country to "UK" and I want it to be windows-1250 if it is in "Poland"
Asked
Active
Viewed 105 times
3
-
As XSLT is also well-formed XML, one way to achieve this is to apply a second XSLT to your original XSLT that updates the encoding on the `xsl:output` element. You can then take the resultant XSLT and apply that to your XML. – Tim C Jul 02 '19 at 12:21
-
Things would be easier if you could upgrade to XSLT 3.0 though (See https://stackoverflow.com/questions/56446836/how-to-dynamically-change-xsloutput-method-attribute-value) – Tim C Jul 02 '19 at 12:22
-
im afraid I cannot use 3.0 because my app relies on the msxml6 and were not allowed to use third party tools or technology, that is why I can only use 1.0 – zyberjock Jul 02 '19 at 13:25
-
I've not actually used it before myself, but you could use MSXML2.MXXMLWriter (See https://stackoverflow.com/questions/6405236/forcing-msxml-to-format-xml-output-with-indents-and-newlines). So, your current XSLT transformation process would need to create a DOMDocment, and then you serialise to a string using MSXML2.MXXMLWriter, setting the encoding as required. – Tim C Jul 03 '19 at 10:03