Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Convert xml file to plain text file >Thread Next - Re: Convert xml file to plain text file Re: Convert xml file to plain text fileTo: NULL Date: 6/14/2007 2:04:00 PM
Hans wrote:
> And then call (from VB6 where doc is a domdocument that contains the xml
> document, stylesheet is also a domdocument holding the styleheet and
> MyStream is a Adodb.Stream object)
> doc.transformNodeToObject stylesheet, MyStream
> MyStream.SaveToFile("c.\test.txt")
>
>
> but the file is always empty.
Do you call Open on the stream first?
Here is a complete VBScript program that works for me:
Dim XmlDoc, XsltProc, Template, Sheet
Set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
Set Sheet = CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
Set Template = CreateObject("Msxml2.XslTemplate.3.0")
Sheet.async = False
If Sheet.load("test2007061401Xsl.xml") Then
XmlDoc.async = False
If XmlDoc.load("test2007061401.xml") Then
Template.stylesheet = Sheet
Set XsltProc = Template.CreateProcessor
XsltProc.input = XmlDoc
Set Stream = CreateObject("ADODB.Stream")
Stream.Open
Stream.Type = 1
XsltProc.output = Stream
XsltProc.Transform
Stream.SaveToFile "test2007061401Result.txt"
Stream.Close
Else
WScript.Echo "Error parsing XML: " & XmlDoc.parseError.reason
End If
Else
WScript.Echo "Error parsing stylesheet: " & Sheet.parseError.reason
End If
XML input is your sample, stylesheet is similar to yours with some
addition to output line breaks:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:apply-templates select="HEADER/ROWS/ROW"/>
</xsl:template>
<xsl:template match="HEADER/ROWS/ROW">
<xsl:value-of select="TEXT" />
<xsl:if test="position() != last()">
<xsl:value-of select="' '"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
