All pastes #960009 Raw Edit

Miscellany

public text v1 · immutable
#960009 ·published 2008-03-27 20:41 UTC
rendered paste body
<div id="example"></div>

if (window.ActiveXObject)// for IE
  {

		// create an ActiveX object
		var xml = new ActiveXObject("Microsoft.XMLDOM")
		// load asynchronically is false, i.e., wait for the file to load before doing anything else
		xml.async = false
		// load the xml document
		xml.load("test.xml")
		
		// create an ActiveX object
		var xsl = new ActiveXObject("Microsoft.XMLDOM")
		// load asynchronically is false, i.e., wait for the file to load before doing anything else
		xsl.async = false
		// load the xsl document
		xsl.load("test.xsl") 

		// document write the result of transforming the XML doc using the XSL doc
		document.write(xml.transformNode(xsl))
  }
 // code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {		
		// create an empty document
		var xml = document.implementation.createDocument('', '', null);
		// load asynchronically is false, i.e., wait for the file to load before doing anything else
		xml.async = false;
		// load the xml document
		xml.load('breakfast.xml');
		
		// create an empty document
		var xsl = document.implementation.createDocument('', '', null);
		// load asynchronically is false, i.e., wait for the file to load before doing anything else
		xsl.async = false;
		// load the xml document
		xsl.load('breakfast.xsl');

		// create a new xslt processor object
		var p = new XSLTProcessor();

		// associate the processor with the loaded xsl file
		p.importStylesheet(xsl);

		// transform the xml file using the imported xsl file
		var t = p.transformToFragment(xml, document);
		
		//add the result of the transformation to the current document by appending it to an HTML element in the current page
		document.getElementById("example").appendChild(t);	
  
  }
else
  {
  	alert('Your browser cannot handle this script');
  }