Microsoft used to have a nice utility called MSXSL.EXE that allowed you to do xsl transformations on the command line. For some reason, that program is no longer available from Microsoft so I hacked together a script to do transformations.
var sXMLFile;
var sXSLFile;
var sOutputFile;
var oArgs = WScript.Arguments;
var WshShell = WScript.CreateObject ("WScript.Shell");
try
{
sXMLFile = oArgs(0);
}
catch (err)
{
WScript.Echo("No XML file specified. Trying input.xml.");
sXMLFile = WshShell.CurrentDirectory + "\\input.xml";
}
try
{
sXSLFile = oArgs(1);
}
catch (err)
{
WScript.Echo("No XSL file specified. Trying default.xsl.");
sXSLFile = WshShell.CurrentDirectory + "\\default.xsl";
}
try
{
sOutputFile = oArgs(2);
}
catch (err)
{
WScript.Echo("No Output file specified. Trying output.txt.");
sOutputFile = WshShell.CurrentDirectory + "\\output.txt";
}
var oFilesystem = new ActiveXObject("Scripting.FileSystemObject");
try
{
var oOutputFile = oFilesystem.CreateTextFile(sOutputFile);
}
catch (err)
{
WScript.Echo(err.description);
}
var xml, xslt;
try
{
xml = new ActiveXObject("MSXML2.DOMDocument.4.0");
xml.validateOnParse = true;
xml.async = false;
xml.load(sXMLFile);
xslt = new ActiveXObject("MSXML2.DOMDocument.4.0");
xslt.validateOnParse = true;
xslt.async = false;
xslt.load(sXSLFile);
output = xml.transformNode(xslt);
oOutputFile.Write(output);
}
catch(err)
{
WScript.Echo(err.description)
}
You may also run it from a command line. When running from the command line or from the 'run' dialog you may pass in your documents as arguments as in the following example.
msxsl.js myInput.xml myTransform.xsl myOutput.txt
Even if you run the script from a command line, error messages will be displayed in popup dialogs. To force the script to send output to the console, you must run it with cscript as shown in the following example.
cscript c:\msxsl.js
That's fine, but I don't like to type all of that so I created a file called msxsl.cmd and in it, placed the following.
@echo off
cscript //nologo c:\msxsl.js %1 %2 %3
I threw it in a directory that was already in my path so it's always found. Now all I have to do is type msxsl from a command line and it runs.
Even better, I set it up with EmEditor to run as an external tool and I pass in the current XSL I'm working on.
The MSXSL.JS script probably requires MSXML 4.0.