/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ dojo.provide("dojo.xml.XslTransform"); dojo.xml.XslTransform = function(/*String*/xsltUri){ // summary: // dojo.xml.XslTransform is a convenience object that takes the URI // String of an XSL file as a constructor argument. After each // transformation all parameters will be cleared. Transformation is // supported by IE, Mozilla, and partially by Opera. Other browsers // (notably Safari) have not yet exposed their transformation // primtives well enough to be useful. // xsltUri: // Url of the xslt document to transform nodes with. Transformation is // acheived with the transformTo* methods on instances of this class. dojo.debug("XslTransform is supported by Internet Explorer and Mozilla, with limited support in Opera 9 (no document function support)."); var IS_IE = dojo.render.html.ie; var ACTIVEX_DOMS = [ "Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM" ]; var ACTIVEX_FT_DOMS = [ "Msxml2.FreeThreadedDOMDocument.5.0", "MSXML2.FreeThreadedDOMDocument.4.0", "MSXML2.FreeThreadedDOMDocument.3.0" ]; var ACTIVEX_TEMPLATES = [ "Msxml2.XSLTemplate.5.0", "Msxml2.XSLTemplate.4.0", "MSXML2.XSLTemplate.3.0" ]; function getActiveXImpl(activeXArray){ for(var i=0; i < activeXArray.length; i++){ try{ var testObj = new ActiveXObject(activeXArray[i]); if(testObj){ return activeXArray[i]; } }catch(e){} } dojo.raise("Could not find an ActiveX implementation in:\n\n " + activeXArray); } if(xsltUri == null || xsltUri == undefined){ dojo.raise("You must pass the URI String for the XSL file to be used!"); return false; } var xsltDocument = null; var xsltProcessor = null; if(IS_IE){ xsltDocument = new ActiveXObject(getActiveXImpl(ACTIVEX_FT_DOMS)); xsltDocument.async = false; }else{ xsltProcessor = new XSLTProcessor(); xsltDocument = document.implementation.createDocument("", "", null); xsltDocument.addEventListener("load", onXslLoad, false); } xsltDocument.load(xsltUri); if(IS_IE){ var xslt = new ActiveXObject(getActiveXImpl(ACTIVEX_TEMPLATES)); xslt.stylesheet = xsltDocument; xsltProcessor = xslt.createProcessor(); } function onXslLoad(){ xsltProcessor.importStylesheet(xsltDocument); } function getResultDom(xmlDoc, params){ if(IS_IE){ addIeParams(params); var result = getIeResultDom(xmlDoc); removeIeParams(params); return result; }else{ return getMozillaResultDom(xmlDoc, params); } } function addIeParams(params){ if(!params){ return; } for(var i=0; i