How do you save translated XML to an actual file on disk? I am new to XML/XSLT and I am trying to figure that out. I can't seem to find any examples that work for me. For example, I just want to save the file to c:\temp\text.xls. How to I save it? Do I have to use java or .net or some other programming language/api? I was hoping to have the XSL just save the file.
4 Answers
The XSL can't do anything by itself. It's just a definition for transforming an XML file into something else. To do anything with it you need to run the XSL Transform in a program, or using a tool like XML Spy.
Update
Here's a simple example I wrote some years ago in VBScript:
Dim xml, xsl, htm, fso, flOut
Set xml = CreateObject("MSXML2.DOMDocument")
Set xsl = CreateObject("Msxml2.DOMDocument")
Set fso = CreateObject("Scripting.FileSystemObject")
xml.load WScript.Arguments(0)
xsl.load WScript.Arguments(1)
htm = xml.transformNode(xsl)
Set flOut = fso.CreateTextFile(WScript.Arguments(2))
flOut.Write htm
flOut.close
I called it xmlTrfm.vbs. Use it like this:
xmlTrfm.vbs [sourceFileName].xml [transformFileName].xsl [outputFileName].[ext]
The file extension for the output file name obviously depends on the format that the XSL transform produces, usually xml, html or txt, but can be almost anything.

- 2,331
- 1
- 20
- 18

- 32,176
- 5
- 81
- 116
-
Thank you for the sample code as well. This is most appreciated. This is exactly what I want to know. – dashrader May 17 '12 at 15:25
Almost every XSLT processor allows a transformation to be initiated from the command line. One of the arguments is the file where to save the result of the transformation.
Examples:
Saxon 9.x:
java net.sf.saxon.Transform -s:source -xsl:stylesheet -o:output
MSXML6:
msxsl.exe %xml% %xsl% -o %out% -u '6.0' -t %param[ name="value"]%
XQSharp:
xslt.exe -s %xml% -o %out% -r 1 -t %xsl% %param[ name="value"]%
.NET 2.0+ (XslCompiledTransform):
nxslt2.exe %xml% %xsl% -t -o %out%%param[ name="value"]%
AltovaXML (XML-SPY):
AltovaXML.exe -xslt2 %xsl% -in %xml% -out %out%%param[ name="value"]%
In 2. to 5. above %xml%
is the path to the file containing the XML document, %xsl%
is the path to the file containing the primary XSLT stylesheet, `%out% is the path to the file where the result of the transformation should be saved.

- 240,661
- 26
- 293
- 431
-
Thank you very much. This is also perfect for what I needed to accomplish. Now it's in the knowledge base and others can find it. – dashrader May 17 '12 at 15:26
Perhaps (I'm speculating) your difficulty is that you are running the XSLT transformation in a browser? In that case you will have difficulties because browsers, for security reasons, don't allow writing to filestore in the normal way.
If that's not the case, please explain how you are running your XSLT transformation.

- 156,231
- 11
- 92
- 164
-
You are correct, I was running in a browser. As I said, I am very new to this stuff and I had no idea about the browser limitation. You know how it goes at work...make this happen...but I haven't done it before...then learn it. Make it happen...Does someone out there know how to... haha – dashrader May 17 '12 at 15:23