RE: [xsl] XML transformation output to be in NON UTF-16 on MSXML 3.0.

Subject: RE: [xsl] XML transformation output to be in NON UTF-16 on MSXML 3.0.
From: "Rupesh Chavan" <Rupesh.Chavan@xxxxxxxxxxxxxxx>
Date: Wed, 24 Jul 2002 09:11:57 +0530
=================START OF REPLY============================
jeni wrote:
><xsl:output encoding="Shift-JIS" />


>but that only has an effect if the XSLT processor has control of the
>serialization of the result constructed through the transformation.


>When you use MSXML to run a transformation, if you access the result
>of the transformation as a string, the string is always in UTF-16
>because MSXML's XSLT processor isn't in charge of the serialization.
>To put the XSLT processor in charge of the serialization, and thus get
>a different encoding, you need to send the result of the
>transformation to an object rather than access it as a string. See the
>MSXML documentation on the 'output' property of IXSLProcessor for a
>description.
..................
yes. that is the only statment of hope: the output property. And the only
way is by giving it the custom output.
Meaning, we need to get an object which can serve as an acceptor of the
output.
So here goes the tests for such an object: (x-sjis is an alias for
SHIFT-JIS)


<html>
<META http-equiv="Content-Type" content="text/html; charset=x-sjis">
<button onclick="tryTranformations()">Try the transformations</button>





<xml id="style">
<?xml version="1.0" encoding="x-sjis"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version
="1.0">
   <xsl:output method="html" encoding="x-sjis" />
   <xsl:param name="param1"/>
  <xsl:template match="/">
      <some>something here<xsl:value-of select="." /> after</some>
  </xsl:template>
</xsl:stylesheet>
</xml>





<xml id=xmlDoc>
  <?xml version="1.0" encoding="x-sjis"?>
  <books>
    <book isbn="0345374827">
      <title>The Great Shark Hunt</title>
      <author>Hunter S. Thompson</author>
    </book>
</books>
</xml>





<script language=JScript>
function tryTranformations() {
//the transformNode cannot be used,
//the loadXML method cannot be used
//the .xml method cannot be used
//because all of hte above return only UTF-16 string as per the
//Q275883 support INFO document.
//So the only avenue open is to use the output method of the
IXSLTProcessor.





var xslt = new ActiveXObject("Msxml2.XSLTemplate");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
var xslProc;
xslDoc.async = false;
xslDoc.loadXML(document.all.style.xml);
xslt.stylesheet = xslDoc;
/*
//cannot use the three lines below, because the specification states
that
the loadXML method
//takes as input only the BSTR which is of UTF-16 format.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.loadXML(document.all.source.xml);*/
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc.XMLDocument;
var xmlSink = new ActiveXObject("Msxml2.DOMDocument");





//The documenation says that if we try to read the property, then its
converted into UTF-16.
//So trying to give as input any of the objects which can work with the
ISream interface write method.
try {
   xslProc.transform();
   xslProc.output(xmlSink);
   alert("SUCCESSFUL in serialising in xmlSink DOM object ");
} catch (e)  {
   alert("Cannot be serialised in xmlSink DOM object " +
e.description);
}





try {
   xslProc.transform();
   xslProc.output(xmlSink.load);
   alert("SUCCESSFUL in serialising in xmlSink Load method ");
} catch (e) {
    alert("Cannot be serialised in xmlSink load method " +
e.description);
}





try {
   xslProc.transform();
   xslProc.output(xmlSink.loadXML);
   alert("SUCCESSFUL in serialising in xmlSink LoadXML method ");
} catch (e) {
   alert("Cannot be serialised in xmlSink loadXML method " +
e.description);
}





try {
   xslProc.transform();
   xslProc.output(document); //might be document.write used IStream
   alert("SUCCESSFUL in serialising in document object ");
} catch (e) {
   alert("Cannot be serialised in document object " + e.description);
  }





//So any way to get the output of the transformation only in SHIFT_JIS
}
</script>
</html>






==================END OF REPLY==============================





-----Original Message-----
From: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx]
Sent: Tuesday, July 23, 2002 2:08 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] XML transformation output to be in NON UTF-16 on MSXML
3.0.





Brad Miller wrote:
> I just read this in the Microsoft XML 4.0 parser SDK help.
> If you want the output to be SHIFT-JIS you need to declare it like
> this <?xml version="1.0" encoding="Shift-JIS"?>
> I would assume that this is the same for 3.0 but I can't verify that.


Either the help's wrong or Brad's interpreting it incorrectly (or
perhaps I'm misinterpreting what Brad's saying). The encoding
specified by an XML declaration indicates the encoding for the XML
document in which the XML declaration is used. Changing the encoding
for the stylesheet (what I think Brad's suggesting) will have no
effect on the encoding used in the output of the transformation.


The only thing within XSLT that does have an effect on the encoding
used in the output of the transformation is the encoding attribute on
xsl:output:


<xsl:output encoding="Shift-JIS" />


but that only has an effect if the XSLT processor has control of the
serialization of the result constructed through the transformation.


When you use MSXML to run a transformation, if you access the result
of the transformation as a string, the string is always in UTF-16
because MSXML's XSLT processor isn't in charge of the serialization.
To put the XSLT processor in charge of the serialization, and thus get
a different encoding, you need to send the result of the
transformation to an object rather than access it as a string. See the
MSXML documentation on the 'output' property of IXSLProcessor for a
description.


Cheers,


Jeni


---
Jeni Tennison
http://www.jenitennison.com/





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread