home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 September / INTERNET107.ISO / pc / software / windows / utils / tiny_firewall / tpf45.exe / Data1.cab / prepare.js < prev    next >
Encoding:
Text File  |  2003-03-31  |  2.1 KB  |  86 lines

  1.  
  2. function TransformXML(xml, xslDoc)
  3. {
  4.     //load the stylesheet as a DOMDocument.
  5.     var xslProc;
  6.  
  7.     //Create SAX writer.
  8.     var xmlWriter = new ActiveXObject("Msxml2.MXXMLWriter.4.0");
  9.         
  10.     var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
  11.     
  12.     //Connect the XSLTemplate object to stylesheet DOMDocument.
  13.     xslt.stylesheet = xslDoc;
  14.     
  15.     //Create XSLT processor using stylesheet for XSL template.
  16.     xslProc = xslt.createProcessor();
  17.     
  18.     //Assign XML sample file as input of the transform() method.
  19.     xslProc.input = xml;
  20.     
  21.     //Use a SAX writer as the output of the transform() method.
  22.     xslProc.output = xmlWriter;
  23.     
  24.     //Do transformation on the sample XML file.
  25.     xslProc.transform();
  26.  
  27.     //Use SAX writer ouptut 
  28.     return  xmlWriter.output;
  29.  
  30. function getXsltFile ()
  31. {
  32.   xsltfile ="";
  33.   
  34.   args = WScript.Arguments;
  35.   if (args.length == 0)
  36.   {
  37.      WScript.Echo("Missing module argument");
  38.   }
  39.   else
  40.   {
  41.     Modules  = args(0);
  42.     switch (Modules)
  43.     {
  44.     case "1": xsltfile = "defsbx.xslt"; break;
  45.     case "2": xsltfile = "deffw.xslt"; break;
  46.     case "3": xsltfile = "def.xslt";  break;
  47.     };
  48.   }
  49.   return xsltfile;
  50. }
  51. //main program function
  52. function main()
  53. {
  54.     //Create XML file  as a DOMDocument.
  55.     var xmlSrc = new ActiveXObject("Msxml2.DOMDocument.4.0");
  56.     //Create the stylesheet as a DOMDocument.
  57.     var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
  58.     //Create target  XML file  as a DOMDocument.
  59.     var xmlTarget = new ActiveXObject("Msxml2.DOMDocument.4.0");
  60.     xslDoc.async = false;
  61.     xmlSrc.async = false;
  62.         
  63.     if (!xmlSrc.load("../fncIDs.xml"))
  64.     {
  65.         WScript.Echo ("Error: fncIDs.xml not found");        
  66.         return;
  67.     }
  68.   //get xslt file according argument in script
  69.   xsltfile = getXsltFile();
  70.   if (xsltfile !="")
  71.   {
  72.     //load xslt file
  73.        if (!xslDoc.load(xsltfile))
  74.       {
  75.           WScript.Echo ("Error:", xsltfile," file not found: ");
  76.           return;        
  77.       }
  78.     //run transformation to get result xml file
  79.       xmlTarget.loadXML( TransformXML(xmlSrc, xslDoc));
  80.       xmlTarget.save("def.xml");
  81.   }
  82. }
  83.  
  84. //script entry point
  85. main();