Jump to content
vipasane

Character encoding coversions through xslt

Recommended Posts

If my source xml file has encoding="ISO-8859-1" is there a way to convert it forexample to UTF-8 though XSLT ?If so how could that be done?Thank you for reading so far, any help would be appreciated

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

So yep silly me, thanks for your help and for clearing this up for me.It turned out that I already implemented this.This is what you get when you don't fully understand technology or method you're utilizing

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...