1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
//original author declares xlstransformjs.js public domain
var oArgs = WScript.Arguments;
if (oArgs.length == 0)
{
WScript.Echo ("Usage : cscript xsltransformjs.js x3d xsl out");
WScript.Quit();
}
xmlFile = oArgs(0); //+ ".xml";
xslFile = oArgs(1); //+ ".xsl";
wrlFile = oArgs(2);
var xsl = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
var xml = new ActiveXObject("MSXML2.DOMDocument.6.0");
xml.validateOnParse = false;
xml.async = false;
// next few lines from dug, in anticipation of problems with DTD, scripts etc
// http://msdn.microsoft.com/en-us/library/ms763800(VS.85).aspx
xml.setProperty("AllowDocumentFunction", true);
xml.setProperty("AllowXsltScript", true);
xml.resolveExternals = true;
xml.setProperty("ProhibitDTD", false); //if you have a <DTD> line in your X3D file
//end dug lines
xml.load(xmlFile);
if (xml.parseError.errorCode != 0)
WScript.Echo ("XML Parse Error : " + xml.parseError.reason);
//how to do: x3d Collision enabled='true' --> vrml97 Collision collide TRUE
xsl.async = false;
// next few lines from dug, in anticipation of problems with DTD, scripts etc
// http://msdn.microsoft.com/en-us/library/ms763800(VS.85).aspx
xsl.setProperty("AllowDocumentFunction", true);
xsl.setProperty("AllowXsltScript", true);
xsl.resolveExternals = true;
xsl.setProperty("ProhibitDTD", false); //for JScript
//end dug lines
xsl.load(xslFile);
if (xsl.parseError.errorCode != 0)
WScript.Echo ("XSL Parse Error : " + xsl.parseError.reason);
try
{
//WScript.Echo (xml.transformNode(xsl.documentElement));
var str = xml.transformNode(xsl.documentElement);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile(wrlFile, true);
a.Write(str);
a.Close();
//WScript.StdOut.Write(str);
}
catch(err)
{
WScript.Echo ("Transformation Error : " + err.number + "*" + err.description);
}
|