Share via


Source: XSLT.js

 

This topic provides JScript code.

JScript Source File (XSLT.js)

main();

function main()
{
  var doc = LoadDOM("test.xml");
  var xsl = LoadDOM("test.xsl");

  var str = doc.transformNode(xsl);
  alert("\ndoc.transformNode:\n"+str);

  var out = MakeDOM(null);
  doc.transformNodeToObject(xsl, out);
  alert("\ndoc.transformNodeToObject:\n"+out.xml);
}

function LoadDOM(file)
{
   var dom;
   try {
     dom = MakeDOM(null);
     dom.load(file);
   }
   catch (e) {
     alert(e.description);
   }
   return dom;
}

function MakeDOM(progID)
{
  if (progID == null) {
    progID = "msxml2.DOMDocument.6.0";
  }

  var dom;
  try {
    dom = new ActiveXObject(progID);
    dom.async = false;
    dom.validateOnParse = false;
    dom.resolveExternals = false;
  }
  catch (e) {
    alert(e.description);
  }
  return dom;
}

function alert(str)
{
  WScript.Echo(str);
}

To add XSLT.js to the project

  1. Copy the code listing above. Paste it into the JScript code editor, and save the file as XSLT.js in the current project folder.

Next, we'll add the resource files to the project.