function XSLTHelper( xmlURL, xslURL  ) {
   this.xmlURL = xmlURL;
  
   this.xslURL = xslURL;
   
}

XSLTHelper.isXSLTSupported = function() {
   return (window.XMLHttpRequest && window.XSLTProcessor ) ||
          XSLTHelper.isIEXmlSupported();
}

XSLTHelper.isIEXmlSupported = function() {
   if ( ! window.ActiveXObject )
      return false;
   try { new ActiveXObject("Microsoft.XMLDOM");  return true; }
   catch(err) { return false; }
}

XSLTHelper.prototype = {

   loadView: function(container) {
      if ( ! XSLTHelper.isXSLTSupported() )
         return;
	  
      this.xmlDocument   = null;
      this.xslStyleSheet = null;
      this.container     = $(container);

      new Ajax.Request( this.xmlURL,
                        {onComplete: this.setXMLDocument.bind(this)} );
      new Ajax.Request( this.xslURL,
                        {method: "GET",
                        onComplete: this.setXSLDocument.bind(this)} );
   },

   setXMLDocument: function(request) {
      this.xmlDocument = request.responseXML;
      this.updateViewIfDocumentsLoaded();
   },

   setXSLDocument: function(request) {
      this.xslStyleSheet = request.responseXML;
      this.updateViewIfDocumentsLoaded();
   },

   updateViewIfDocumentsLoaded: function() {
      if ( this.xmlDocument == null || this.xslStyleSheet == null )
         return;
      this.updateView();
	  return true;
   },

   updateView: function () {
      if ( ! XSLTHelper.isXSLTSupported() )
         return;

     if ( window.XMLHttpRequest && window.XSLTProcessor )
         this.updateViewMozilla();
      else if ( window.ActiveXObject )
         this.updateViewIE();
   },

   updateViewMozilla: function() {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(this.xslStyleSheet);
      var fragment = xsltProcessor.transformToFragment(this.xmlDocument, document);	
      this.container.innerHTML = "";
      this.container.appendChild(fragment);
	 
   },

   updateViewIE: function(container) {
   	  
      this.container.innerHTML = this.xmlDocument.transformNode(this.xslStyleSheet);
	 
   }

}





//ȥ����ո�; 
function ltrim(s){ 
return s.replace( /^\s*/, ""); 
} 
//ȥ���ҿո�; 
function rtrim(s){ 
return s.replace( /\s*$/, ""); 
} 
//ȥ�����ҿո�; 
function trim(s){ 
return rtrim(ltrim(s)); 
}
