function importXML(XMLfile,XSLfile){
	if (debug) alert("Before Importing "+XMLfile +", and "+ XSLfile);
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xslDoc = document.implementation.createDocument("", "", null);

		// xmlDoc.onload = createTable;
		xmlDoc.onload = insertXML;
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xslDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
		  // 0 Object is not initialized
		  // 1 Loading object is loading data
		  // 2 Loaded object has loaded data
		  // 3 Data from object can be worked with
		  // 4 Object completely initialized
			// if (xmlDoc.readyState == 4) createTable()
			if (xmlDoc.readyState == 4) insertXML();
		};
 	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
		// Load XSL
	if (debug) alert("Loading "+XSLfile);		
	// xslDOC.async = false
	xslDoc.load(XSLfile);

	// load xml and transform
	if (debug) alert("Loading "+XSLfile);		
	xmlDoc.load(XMLfile);


   if (xmlDoc.parseError.errorCode != 0) {
        error = xmlDoc.parseError;
        alert('Error parsing XML file:\n' + error.reason + '[' + error.url + ': line ' + error.line + ', col ' + error.linepos + ']');
   }
   // Chargement XSL

	xmlToLoad = "";
	xslToLoad = "";
	 /* reset filename */
}

function insertXML(){
if (debug) alert("inside insertXML "+xslDoc);
document.getElementById('myTable').innerHTML= xmlDoc.transformNode(xslDoc);

}
/**
parse xml file and create the corresponding table 
*/
function createTable() {
   if (debug) alert ("inside createTable from importXML");
	var x = xmlDoc.getElementsByTagName("ligne");
	if (debug) alert ("x="+x);
	var newEl = document.createElement("TABLE");
	newEl.setAttribute('class','patner');
	var tmp = document.createElement("TBODY");
	newEl.appendChild(tmp);
	var row = document.createElement('TR');
	
	for (j=0;j<x[0].childNodes.length;j++)
	{
		if (x[0].childNodes[j].nodeType != 1) continue;
		var container = document.createElement('TH');
		var theData = document.createTextNode(x[0].childNodes[j].nodeName);
		container.appendChild(theData);
		row.appendChild(container);
	}
	tmp.appendChild(row);
	for (i=0;i<x.length;i++)
	{
		var row = document.createElement('TR');
		for (j=0;j<x[i].childNodes.length;j++)
		{
			if (x[i].childNodes[j].nodeType != 1) continue;
			var container = document.createElement('TD');
			var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
			container.appendChild(theData);
			row.appendChild(container);
		}
		tmp.appendChild(row);
	}
	document.getElementById('myTable').appendChild(newEl);
}

function newImportXML(XMLfile,XSLfile,tagId){
if(document.implementation && document.implementation.createDocument){
		// *** Mozilla
		var xsltProcessor = new XSLTProcessor();
		// *** load the XSL file
		var myXMLHTTPRequest = new XMLHttpRequest();
		myXMLHTTPRequest.open("GET", XSLfile, false);
		myXMLHTTPRequest.send(null);
		// *** get the XML document
		xslStylesheet = myXMLHTTPRequest.responseXML;
		xsltProcessor.importStylesheet(xslStylesheet);
		// *** load the xml file
		myXMLHTTPRequest = new XMLHttpRequest();
		myXMLHTTPRequest.open("GET", XMLfile, false);
		myXMLHTTPRequest.send(null);
		var xmlSource = myXMLHTTPRequest.responseXML;
		// *** transform
		var resultDocument = xsltProcessor.transformToFragment(xmlSource, document);
		// document.getElementById(tagId).appendChild(resultDocument);
		document.getElementById(tagId).innerHTML="";
		document.getElementById(tagId).appendChild(resultDocument);
	}else if(window.ActiveXObject){
		// *** IE
		// *** Load XML
		xml = new ActiveXObject("MSXML2.DOMDocument");
		xml.async = false
		xml.load(XMLfile)
		// *** Load XSL
		xsl = new ActiveXObject("MSXML2.DOMDocument");
		xsl.async = false
		xsl.load(XSLfile)
		// *** Transform
		document.getElementById(tagId).innerHTML=xml.transformNode(xsl);
	}else{
		// *** Browser unknown
		alert("Browser unknown");
}

}

