Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

manatlan http://manatlan.online.fr

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

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;
		}

apply XSLT transformation on an XML content with PHP4

$xml: should be an xml content buffer
$xsl: should be an xsl content buffer
$result : will be the result ;-)

    
    $xh = xslt_create();
    $arguments = array('/_xml' => $xml, '/_xsl' => $xsl);
    
    $params = array(
        //~ 'param1' => "hello world",
      );
    
    $result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments,$params);
    
    xslt_free($xh);
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS