Jump to content

Character encoding coversions through xslt


Recommended Posts

You can transform XML to XML with the help of XSLT and you can specify the output enoding:

<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">  <xsl:output method="xml" encoding="UTF-8"/>  <xsl:template match="/">	 <xsl:copy-of select="."/>  </xsl:template></xsl:stylesheet>

Depending on your XML input that approach can have shortcomings however as it does not copy the input unchanged to the output but rather parses the XML input into the tree model of XSLT/XPath and copies that tree to the output. As the XSLT/XPath data model does not model all kind of nodes an XML document can have, such as DOCTYPE nodes or CDATA section nodes, the output can look different from the input (e.g. the DOCTYPE would be dropped and CDATA sections would be replaced with text nodes with escaped characters).

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...