Jump to content

XML/XSL transform into HTML using JavaScript browser independent


henny

Recommended Posts

hello,I've an XML/XSL question, using JavaScript to transform into HTML at client-sidethis JS-code I found at http://www.xmlfiles.com/xsl/xsl_client.asp ( and other sources ) works fine in IE

<script language="javascript"> // Load the XML  var xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = false; xml.load("cd_catalog.xml"); // Load the XSL var xsl = new ActiveXObject("Microsoft.XMLDOM"); xsl.async = false; xsl.load("cd_catalog.xsl"); // Transform document.write(xml.transformNode(xsl)); <script language="javascript">

can someone help me with the equivalent Mozilla Firefox JS-code ?? thx a lot& greetings / groeten - Henny

Link to comment
Share on other sites

due to some searching I've the following codethat works fine on my local disk ( both IE & FF )but doesn't on my server ( only IE, FF is still waiting )http://ourworld.compuserve.com/homepages/h...talog_IE_FF.htm

<div id="xmlData">Please Wait...</div><script type="text/javascript">	var sourceXML = 'cd_catalog.xml';	var sourceXSL = 'cd_catalog.xsl';		// Test Browser's Support 	if(window.ActiveXObject)		{	  // Internet Explorer 		// Load the XML 		var xml = new ActiveXObject("Microsoft.XMLDOM"); 		xml.async = false; 		xml.load(sourceXML); 			// Load the XSL 		var xsl = new ActiveXObject("Microsoft.XMLDOM"); 		xsl.async = false 		xsl.load(sourceXSL); 			// Transform and display 		var writeObj = document.getElementById('xmlData'); 		writeObj.innerHTML = xml.transformNode(xsl);		} 	else if (window.XMLHttpRequest && window.XSLTProcessor)		{ 	// Mozilla Firefox 		// Load the XSL 		var xmlhttpXSL = new XMLHttpRequest(); 		xmlhttpXSL.open("GET", sourceXSL, false); 		xmlhttpXSL.send(null); 		var loadedStyle = xmlhttpXSL.responseXML; 			// Load the XML 		var xmlhttpXML = new XMLHttpRequest(); 		xmlhttpXML.open("GET", sourceXML, false); 		xmlhttpXML.send(null); 		var loadedXML = xmlhttpXML.responseXML; 			// Transform and display 		var xsltProcessor = new XSLTProcessor(); 		xsltProcessor.importStylesheet(loadedStyle); 		var xmls = new XMLSerializer(); 		var xmlDoc = xsltProcessor.transformToDocument(loadedXML); 		var writeObj = document.getElementById('xmlData'); 		writeObj.innerHTML = xmls.serializeToString(xmlDoc); 		}	else		{		var writeObj = document.getElementById('xmlData'); 		writeObj.innerHTML = 'Your browser cannot handle this script';		}</script>

any clue ??thx in advance !!

hello,I've an XML/XSL question, using JavaScript to transform into HTML at client-sidethis JS-code I found at http://www.xmlfiles.com/xsl/xsl_client.asp ( and other sources ) works fine in IE
<script language="javascript"> // Load the XML  var xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = false; xml.load("cd_catalog.xml"); // Load the XSL var xsl = new ActiveXObject("Microsoft.XMLDOM"); xsl.async = false; xsl.load("cd_catalog.xsl"); // Transform document.write(xml.transformNode(xsl)); <script language="javascript">

can someone help me with the equivalent Mozilla Firefox JS-code ?? thx a lot& greetings / groeten - Henny

Link to comment
Share on other sites

I'm guessing you've used the script in this topic? Or at least an older version of it.What exactly did you did to make it work? Could you show the complete code (there).And aalbetski, I've already asked you in a PM I recall. If you could make ANY impovements on that script, PLEASE do. I tryed to myself, but my lack of JS knowledge again leaves me nowhere.

Link to comment
Share on other sites

this is the javascript function I'm using now to process my XML & XSl files

// transform_XML function transform_XML( sourceXML, sourceXSL, innerTag ) 	{	var writeObj = document.getElementById(innerTag);	// Test Browser's Support 	if(window.ActiveXObject)		{	  // Internet Explorer 		// Load the XML 		var xml = new ActiveXObject("Microsoft.XMLDOM"); 		xml.async = false; 		xml.load(sourceXML); 			// Load the XSL 		var xsl = new ActiveXObject("Microsoft.XMLDOM"); 		xsl.async = false 		xsl.load(sourceXSL); 			// Transform and display 		writeObj.innerHTML = xml.transformNode(xsl);		} 	else if (window.XMLHttpRequest && window.XSLTProcessor)		{ 	// Mozilla Firefox 		// Load the XML 		var xml = document.implementation.createDocument("", "", null);		xml.async = false; 		xml.load(sourceXML); 			// Load the XSL 		var xsl = document.implementation.createDocument("", "", null);		xsl.async = false 		xsl.load(sourceXSL); 			// Transform and display 		var xsltProcessor = new XSLTProcessor(); 		xsltProcessor.importStylesheet(xsl); 		var xmls = new XMLSerializer(); 		var xmlDoc = xsltProcessor.transformToDocument(xml); 		writeObj.innerHTML = xmls.serializeToString(xmlDoc); 		}	else		{		writeObj.innerHTML = 'sorry, your browser does not support this...';		}	}

Link to comment
Share on other sites

You may want to get up-to-date on the Microsoft Parser. This code illustrates this usage of MSXML4.dll It will work with later version as well

		<xcript>			function InitPage()			{				//				// demonstrate passing a parameter				//				document.getElementById("display").innerHTML = 	TransformXML(10)			}			function TransformXML(price)			{				var xmlSource		= 	new ActiveXObject("Msxml2.DOMDocument.4.0")				var xslStyle 		=	new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0")				xmlSource.async 	= 	false				xslStyle.async	=	false				xmlSource.load("824.xml")				xslStyle.load("824.xsl")				xslStyle.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'")				var objTransformer	=	new ActiveXObject("Msxml2.XSLTemplate.4.0")				objTransformer.stylesheet = xslStyle.documentElement				var objProcessor = objTransformer.createProcessor()	//				//			pass the parameter through to the stylesheet	//	//			objProcessor.addParameter("price",price,"")				objProcessor.input = xmlSource				objProcessor.transform()				return objProcessor.output			}		</xcript>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...