henny Posted May 14, 2007 Share Posted May 14, 2007 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 More sharing options...
henny Posted May 16, 2007 Author Share Posted May 16, 2007 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 More sharing options...
aalbetski Posted May 16, 2007 Share Posted May 16, 2007 you can use var oXmlDom = document.implementation.createDocument("", "", null); var oXslDom = document.implementation.createDocument("", "", null); oXmlDom.load("your.xml"); oXslDom.load("your.xslt");to load your XML and XSLT.have a look here for some more info:http://www.webreference.com/programming/prof_ajax/3.html Link to comment Share on other sites More sharing options...
henny Posted May 16, 2007 Author Share Posted May 16, 2007 great !!thx a lot now it works in both browsers - locally & on the websitegr. Henny Link to comment Share on other sites More sharing options...
boen_robot Posted May 17, 2007 Share Posted May 17, 2007 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 More sharing options...
henny Posted May 21, 2007 Author Share Posted May 21, 2007 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 More sharing options...
aalbetski Posted May 24, 2007 Share Posted May 24, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.