Over a million developers have joined DZone.

Some Javascript Usefull Functions For Xml/xslt

·
works well on IE/firefox ... (need to be adapted)

		function getDomFromFile(file) {
			// Load XML
			if (typeof ActiveXObject != 'undefined') {// IE
				var xml = new ActiveXObject("Microsoft.XMLDOM");
				xml.async = false;
				xml.load(XML);
			}
			else {	// others
				var myXMLHTTPRequest = new XMLHttpRequest();
				myXMLHTTPRequest.open("GET", XML, false);
				myXMLHTTPRequest.send(null);
				var xml = myXMLHTTPRequest.responseXML;
			}
			return xml;
		}
		
		function getDomFromXml(xml) {

			if (typeof ActiveXObject != 'undefined') {
				var dom = new ActiveXObject("Microsoft.XMLDOM");
				dom.async = false;
				dom.loadXML(xml);
			}
			else {
				parser = new DOMParser();
				dom = parser.parseFromString(xml, "text/xml");						
			}
			return dom;
		}


		function xslt(xmlDoc,xslDoc) {
			var transform;
			
			if (typeof ActiveXObject != 'undefined') {
				transform = xmlDoc.transformNode(xslDoc);
			}
			else {
				var xsl = new XSLTProcessor();
				
				xsl.importStylesheet(xslDoc);
				var fragment=xsl.transformToFragment(xmlDoc, document);
				if( fragment.childNodes.length>0 )
				  transform = fragment.childNodes[0].innerHTML;
				else
					alert("error");
			}
			return transform;
		}
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}