Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // transform.js
- //
- // Analyzing why an MSXML XSLT transformation fails
- // Call the script with the filename (without extension) as arg
- //
- // Start in a cmd shell or in a batch file with:
- //
- // cscript //e:jscript transform.js name
- //
- // Style sheet and XML doc have this filename,
- // but different extensions (name.xsl and name.xml)
- try {
- WScript.StdOut.Write( transform( WScript.Arguments(0) ) );
- } catch (e) {
- WScript.Echo(e.message);
- }
- function transform(fileName) {
- var xmlDocument = get_xmlDocument( fileName + ".xml" );
- var xsltProcessor = get_xsltProcessor( fileName + ".xsl" );
- xsltProcessor.input = xmlDocument;
- xsltProcessor.transform();
- return xsltProcessor.output;
- }
- function get_xmlDocument( xmlfile ) {
- var xmlDocument = new ActiveXObject("Msxml2.DOMDocument.6.0");
- // or Msxml2.DOMDocument.3.0
- xmlDocument.async = false;
- xmlDocument.load( xmlfile );
- if (xmlDocument.parseError.errorCode != 0) {
- throw new Error( src.message );
- }
- return xmlDocument;
- }
- function get_xslDocument( xslfile ) {
- var xslDocument = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
- // or Msxml2.FreeThreadedDOMDocument.3.0
- xslDocument.async = false;
- xslDocument.load( xslfile );
- if (xslDocument.parseError.errorCode != 0) {
- var myErr = xslDocument.parseError;
- throw new Error("XSL parse error: " + myErr.reason);
- }
- return xslDocument;
- }
- function get_xsltProcessor( xslfile ) {
- var xslDocument = get_xslDocument( xslfile );
- var xmlTemplate = new ActiveXObject( "Msxml2.XSLTemplate.6.0" );
- // or Msxml2.XSLTemplate.3.0
- xmlTemplate.stylesheet = xslDocument;
- var xsltProcessor = xmlTemplate.createProcessor();
- return xsltProcessor;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement