	var MyDate=new Date();
	var CurrentYear=MyDate.getFullYear();
	var CurrentMonth=MyDate.getMonth();
	var CurrentDay=MyDate.getDate();
	var CurrentDate=(CurrentYear*10000) + ((CurrentMonth+1)*100) + CurrentDay;

	var XMLDoc, XSLDoc, XSLTemplate;
	var currentSortDirection = "descending";
	var currentSortCol = "";
	var GlobalStrSort = "";
		//XML and XSL files to use
	strXMLFileName="News/XML/News.xml";
	strXSLFileName="XML/rendertopx.xsl";
	
	window.onload=displayResult
	
function displayResult()
{
SetSortDirection('FromDate')
// code for IE
if (window.ActiveXObject)
  {	
	//XMLDoc = new ActiveXObject("Microsoft.XMLDOM"); 
	XMLDoc = new ActiveXObject("MSXML2.DOMDocument.3.0"); 

	XMLDoc.async = false;
	XMLDoc.resolveExternals = false;
	XMLDoc.validateOnParse = false;	
	
	// This is necessary to use XPath in selectSingleNode and selectNodes methods
	// For backwards compatibility, XSL Patterns are default.
	XMLDoc.setProperty("SelectionLanguage", "XPath");
	XMLDoc.load(strXMLFileName);

	XSLDoc = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
	
	XSLDoc.async = false;
	XSLDoc.resolveExternals = false;
	XSLDoc.validateOnParse = false;
XSLDoc.load(strXSLFileName);
    
	XSLTemplate = new ActiveXObject("MSXML2.XSLTemplate");
	XSLTemplate.stylesheet = XSLDoc;
	//alert("Your browser is good enough!");
	
	var objXSLProcessor;
	objXSLProcessor = XSLTemplate.createProcessor();
	objXSLProcessor.input = XMLDoc;

	//Process Params
	objXSLProcessor.addParameter("sortBy",GlobalStrSort);
	objXSLProcessor.addParameter("direction",currentSortDirection);
	objXSLProcessor.addParameter("CDate",CurrentDate);
	
	objXSLProcessor.transform();
	document.getElementById("Result").innerHTML = objXSLProcessor.output;
return(null);
} 
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
	LoadedXML=loadXMLDoc(strXMLFileName);
	LoadedXSL=loadXMLDoc(strXSLFileName);
	xsltProcessor=new XSLTProcessor();
	xsltProcessor.importStylesheet(LoadedXSL);
  	xsltProcessor.setParameter(null,"CDate",CurrentDate);
	xsltProcessor.setParameter(null,"direction",currentSortDirection);
	resultDocument = xsltProcessor.transformToFragment(LoadedXML,document);
	document.getElementById("Result").appendChild(resultDocument);
  }
}

    function applyXSLTWithParam(xmlFileName, xslFileName) 
        { 
            var objXML; 
            var objXSLT; 
            var objxsltTemplate; 
            var objxsltProcessor; 
  
            try 
            {     
                objXML = new ActiveXObject("MSXML2.DOMDocument.3.0"); 
                objXML.async = false; 
                objXML.validateOnParse = false; 
  
                objXSLT = new ActiveXObject("MSXML2.FreeThreadedDOMDocument.3.0"); 
                objXSLT.async = false; 
                objXSLT.validateOnParse = false; 
  
                //Load XML and XSLT documents 
                objXML.load(xmlFileName); 
                objXSLT.load(xslFileName); 
  
                objxsltTemplate = new ActiveXObject("MSXML2.XSLTemplate.3.0"); 
                objxsltTemplate.stylesheet = objXSLT; 
                objxsltProcessor = objxsltTemplate.createProcessor(); 
                objxsltProcessor.input = objXML; 
                objXSLProcessor.addParameter("sortBy",GlobalStrSort);
				objXSLProcessor.addParameter("direction",currentSortDirection);
				objXSLProcessor.addParameter("CDate",CurrentDate);
                objxsltProcessor.transform(); 
				
                return objxsltProcessor.output; 
            } 
            catch(e) 
            { 
                //error handling 
            } 
        } 

		function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
	xhttp=new XMLHttpRequest();
	xhttp.open("GET",dname,false);
	xhttp.send("");
	return xhttp.responseXML; 
  }
else
  {
	xhttp=new ActiveXObject("Microsoft.XMLHTTP");
	xhttp.open("GET",dname,false);
	xhttp.send("");
	return xhttp.responseXML;
  }
}

function SetSortDirection(strSort)
{	// Toggle the sort direction only if necessary
	if (strSort == currentSortCol)
	{	//strSort is CurrentSortCol
		if (currentSortDirection =="ascending")
		{currentSortDirection = "descending";}
		else
		{currentSortDirection = "ascending";}
	}
	else
	{	//strSort is NOT CurrentSortCol
		currentSortCol = strSort;
		currentSortDirection = currentSortDirection;
	}
}

