Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to ensure the output of transform is utf-8 1

Status
Not open for further replies.

ddiamond

Programmer
Apr 22, 2005
918
US
I am using xslt to transform my xml source file into a soap request which I then pass to a web-service. The problem I'm running into is that no matter what I do, the output of the xslt is tagged as utf-16, and the web service only seems to like utf-8. How can I make sure the output is tagged as utf-8?

Here is the header of my xslt file:
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes' />
Eventhough I am specifying UTF-8 in the output element, my output always has the following header.
Code:
<?xml version="1.0" encoding="utf-16"?>
 
What is the encoding of the input document?

What XML/XSLT processor are you using?

Are those really apostrophes in the xsl:eek:utput element attributes? Maybe the processor is not complaining, but not acting on the attributes...

Tom Morrison
 
Are those really apostrophes in the xsl:eek:utput element attributes? Maybe the processor is not complaining, but not acting on the attributes...
Yes, they are apostrophes. After reading your comment I tried switching them to double quotes, but it did not make a difference.


The input document's encoding = UTF-8. I'm not sure which xml/xslt processor I'm using, but here is my javascript code:
Code:
function Translate(XMLFileName, XSLFileName)
{
  // Load XML 
  var xml = new ActiveXObject("Microsoft.XMLDOM");
  xml.async = false;
  xml.load(XMLFileName); 
  
  // Load XSL
  var xsl = new ActiveXObject("Microsoft.XMLDOM");
  xsl.async = false;
  xsl.load(XSLFileName);
  
  // Transform
  return xml.transformNode(xsl);
}
 
In case utf-8 is the target encoding, the simplest you can do is to use transformnodetoobject method.
[tt]
function Translate(XMLFileName, XSLFileName)
{
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.load(XMLFileName);

// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
xsl.load(XSLFileName);

[blue]//adding this
var outxml=new ActiveXObject("Microsoft.XMLDOM");
outxml.async=false;[/blue]

// Transform
[red]//[/red]return xml.transformNode(xsl);
[blue]xml.transformNodeToObject(xsl,outxml);
return outxml.xml;[/blue]
}
[/tt]
 
Thanks tsuji. I'll give it a try and let you know.
 
tsuji,

That did the trick. It also indented the output which was nice. It looks like the transformNode method ignored my output element, but the transformNodeToObject did not ignore it. Thanks for your help.

- Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top