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)
   1  
   2  		function getDomFromFile(file) {
   3  			// Load XML
   4  			if (typeof ActiveXObject != 'undefined') {// IE
   5  				var xml = new ActiveXObject("Microsoft.XMLDOM");
   6  				xml.async = false;
   7  				xml.load(XML);
   8  			}
   9  			else {	// others
  10  				var myXMLHTTPRequest = new XMLHttpRequest();
  11  				myXMLHTTPRequest.open("GET", XML, false);
  12  				myXMLHTTPRequest.send(null);
  13  				var xml = myXMLHTTPRequest.responseXML;
  14  			}
  15  			return xml;
  16  		}
  17  		
  18  		function getDomFromXml(xml) {
  19  
  20  			if (typeof ActiveXObject != 'undefined') {
  21  				var dom = new ActiveXObject("Microsoft.XMLDOM");
  22  				dom.async = false;
  23  				dom.loadXML(xml);
  24  			}
  25  			else {
  26  				parser = new DOMParser();
  27  				dom = parser.parseFromString(xml, "text/xml");						
  28  			}
  29  			return dom;
  30  		}
  31  
  32  
  33  		function xslt(xmlDoc,xslDoc) {
  34  			var transform;
  35  			
  36  			if (typeof ActiveXObject != 'undefined') {
  37  				transform = xmlDoc.transformNode(xslDoc);
  38  			}
  39  			else {
  40  				var xsl = new XSLTProcessor();
  41  				
  42  				xsl.importStylesheet(xslDoc);
  43  				var fragment=xsl.transformToFragment(xmlDoc, document);
  44  				if( fragment.childNodes.length>0 )
  45  				  transform = fragment.childNodes[0].innerHTML;
  46  				else
  47  					alert("error");
  48  			}
  49  			return transform;
  50  		}

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

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