Home Forums General XMetaL Discussion Code Request: Process content with XSLT Reply To: Code Request: Process content with XSLT

ghkrause

Reply to: Code Request: Process content with XSLT

When running JScript in Internet Explorer to render a preview I use the function below. It will transform XML by MSXML engine. Hope this helps and gets you going. I never tried it inside an XMetaL macro, though. You will have to replace the initialization of xml_source with your valid XML trunk and convert the result to XML via the load method …
[code]function xml_convert( strXmlSourceUrl, strXslPath ) {
  var xml_source = new ActiveXObject(“Msxml2.DOMDocument”);
  xml_source.async = false;
  xml_source.validateOnParse = false;
  xml_source.resolveExternals = blnResolveExternals;
  // use this to load a file (a path) to the MSXML
  xml_source.load( strXmlSourceUrl );
  // load XSLT stylesheet document
  var stylesheet = new ActiveXObject(“Msxml2.DOMDocument”);
  stylesheet.async = false;
  stylesheet.validateOnParse=false;
  stylesheet.load( strXslPath );
  // transform the source using the XSLT stylesheet
  var converted_html = “”;
  try {
    converted_html = xml_source.transformNode( stylesheet );
  }
  catch( err ) {
    converted_html = “Error transforming with ” + strXslPath + “. ” + err.decsription;
    for (var i in err) {
      converted_html=converted_html+” “+ err+”. “;
    }
    alert(converted_html);
  }
  return converted_html;
}[/code]

Reply

Products
Downloads
Support