/*
 * xslt.js
 *
 * 2002, 2005
 *
 * Author: Johann Burkard - http://johannburkard.de
 *
 * Version 1.0
 *
 * XSL Transformations.
 */

/**
 * Browser supports XSLT.
 */
function browserSupportsXSLT() {
 var support = false;
 if (document.recalc) { // IE 5+
  support = true;
 }
 if (typeof XMLHttpRequest != 'undefined' && typeof XSLTProcessor != 'undefined'
  && typeof DOMParser != 'undefined' && typeof XMLSerializer != 'undefined') { // Mozilla 0.9.4+, Opera 9+
  support = true;
 }
 return support;
}

/*
 * Transform XML text and XSL text into the targetElement.
 * 
 * @param xml XML text or ID of the element containing XML (for IE)
 * @param xsl XSL text or ID of the element containing XSL (for IE)
 * @param xslParam doble array, params for the XSL document
*/
  function xsltTransform(xmlDoc, xslDoc, xslParams){
	  var resultado,docCache,docProcessor;
    if (document.recalc) {       // IExplorer
      var xslIE = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
      xslIE.async = false;
      xslIE.load(xslDoc);
      docCache = new ActiveXObject("MSXML2.XSLTemplate");
      docCache.stylesheet = xslIE;
      // instantiate the document processor and submit the xml document
      docProcessor = docCache.createProcessor();
      docProcessor.input = xmlDoc;
      // add parameters to the xsl document
      for (var i=0;i<xslParams.length;i++){
        docProcessor.addParameter(xslParams[i][0],xslParams[i][1], "");
      }
      // process the documents into html and submit to the passed div to the HMTL page
      docProcessor.transform();
      resultado = docProcessor.output;
    } else {                    // Mozilla
      var xsl = new XSLTProcessor();
      for (var i=0;i<xslParams.length;i++){
        xsl.setParameter(null,xslParams[i][0],xslParams[i][1]);
      }
      xsl.importStylesheet(xslDoc);
      var fragment=xsl.transformToFragment(xmlDoc, document);
      resultado = (new XMLSerializer()).serializeToString(fragment);
    }
    return resultado
  }


