Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Text output with MSXML?

From: Martin Honnen <Martin.Honnen@--------.-->
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/




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent