Re: [xsl] XML to XML to HTML Transformation using file protocol

Subject: Re: [xsl] XML to XML to HTML Transformation using file protocol
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 17 Dec 2001 22:18:17 +0000
Hi Rich,

> Problem is going from 'testtoXML.xsl' to 'testtoHTML.xsl'. The
> archive shows a similar question that doesn't fix my problem. This
> must be accomplished with an client based XSLT processor(i.e. IE6 or
> IE5.x w/MSXML3). Please help!

Once Internet Explorer has activated its automatic transformation
(looking at the xml-stylesheet PI and using the stylesheet that it
indicates), the browser views whatever the transformation has
generated as HTML. It does not try to parse the result as XML again,
does not read any xml-stylesheet processing instruction you include,
and doesn't even apply the default stylesheet that gives you the nice
tree structure you usually get when you open a saved XML file.

So if you want to do a two-step transformation on the client, you have
to write the script to run it. Something like:

  function createDocumentObject() {
    var DOM = new ActiveXObject('MSXML2.FreeThreadedDOMDocument');
    DOM.async = false;
    DOM.validateOnParse = false;
    DOM.preserveWhiteSpace = true;
    return DOM;
  }

  // Create Document objects
  var xml1DOM = createDocumentObject();
  var xsl1DOM = createDocumentObject();
  var xml2DOM = createDocumentObject();
  var xsl2DOM = createDocumentObject();
     
  // Load XML and stylesheet documents
  xmlDOM.load('test.xml');
  xsl1DOM.load('testtoXML.xsl');
  xsl2DOM.load('testtoHTML.xsl');

  // Run the first transformation
  var xsl1Template = new ActiveXObject('MSXML2.XSLTemplate');
  xsl1Template.stylesheet = xsl1DOM;
  var xsl1Processor = xsl1Template.createProcessor();
  xsl1Processor.input = xml1DOM;
  xsl1Processor.output = xml2DOM;
  xsl1Processor.transform();

  // Run the second transformation
  var xsl2Template = new ActiveXObject('MSXML2.XSLTemplate');
  xsl2Template.stylesheet = xsl2DOM;
  var xsl2Processor = xsl2Template.createProcessor();
  xsl2Processor.input = xml2DOM;
  xsl2Processor.transform();

  // Write the resulting HTML to the document
  document.write(xsl2Processor.output);

But probably you should put some error catching in there.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread