Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Text output with MSXML? >Thread Next - Re: Text output with MSXML? Re: Text output with MSXML?To: NULL Date: 7/1/2004 5:12:00 PM Note this is a repost as the previous post didn't show up.
Andreas Baus wrote:
> I have a problem with creating text output from XSL transformations.
> Basically, when I use code like
>
> oXMLDoc.transformNodeToObject(oXSLDoc, oXMLDoc);
> oXMLDoc.save(strOutputFileName);
>
> the resulting file is always empty, if the XSL has
> <xsl:output method="text"> (things are fine for xml and html output
> methods).
>
> If I use the transformNode method instead to write the result to a string,
> then write the string to a file, it works for text output, but causes a lot
> of problem with character encoding. Is there a better way to handle XSL
> transformations that can deal with all output methods without requiring
> special case treatment?
If you pass an XML DOM document object as the second parameter to
transformNodeToObject it tries to parse the result of the transformation
and text output is not parsable as XML thus you can't get a proper
result that way. According to the documentation you can also pass a
stream as the second argument so that is probably a way to have text
output while avoiding transformNode.
Here is an example using JScript with Windows Script Host:
var xmlDocument = WScript.CreateObject('Msxml2.DOMDocument.4.0');
xmlDocument.async = false;
xmlDocument.load('test20040701.xml');
var xslDocument = WScript.CreateObject('Msxml2.DOMDocument.4.0');
xslDocument.async = false;
xslDocument.load('test2004070101Xsl.xml');
var adoStream = WScript.CreateObject('ADODB.Stream');
adoStream.Open();
adoStream.Type = 1;
xmlDocument.transformNodeToObject(xslDocument, adoStream);
adoStream.SaveToFile('test2004070101Result.txt', 2);
adoStream.Close();
xslDocument.load('test2004070102Xsl.xml');
adoStream.Open();
adoStream.Type = 1;
xmlDocument.transformNodeToObject(xslDocument, adoStream);
adoStream.SaveToFile('test2004070102Result.txt');
adoStream.Close();
The example XML file is
<?xml version="1.0" encoding="UTF-8"?>
<text xml:lang="de">Umlaute: äöü.</text>
the XSL is
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:template match="/">
<xsl:value-of select="text" />
</xsl:template>
</xsl:stylesheet>
where the second XSL differs only in the output encoding="ISO-8859-1".
When I run that and later examine the output files with a text editor
the first is indeed UTF-8 encoded, the second ISO-8859-1 encoded.
The docs for an ADODB.Stream object are at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdobjstream.asp
Please give some feedback in the group whether that approach works for
you and in which context you use it (ASP or Windows Script Host or VB or
even C++).
Note that I haven't tested transformNodeToObject with a stream output
object for the XSLT output method xml.
--
Martin Honnen
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
