在firefox中,如何用Javascript 为xml文件分配xsl模板,并另外加入自定义的参数?
wuan 2008-09-28 05:31:23 在IE中的实现已经有了,代码如下
<script type="text/javascript" language="JavaScript">
// Function loadSource
// ---------------------------------------------------------------
// This functions loads an XML file as an ActiveXObject
// Gets a path to an XML file as parameter
// Returns the ActiveXObject
function loadSource(XMLFile) {
var xmlDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0");
xmlDoc.async=false;
xmlDoc.load(XMLFile);
return xmlDoc;
}
// Function getProcessor
// ----------------------------------------------------------------
// This function loads an XSL file and creates a processor
// Gets a path to an XSL file as parameter
// Returns the processor
function getProcessor(XSLFile){
var xslDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0");
var xslTemplate=new ActiveXObject("Msxml2.XSLTemplate.5.0");
xslDoc.async=false;
xslDoc.load(XSLFile);
xslTemplate.stylesheet=xslDoc;
xslProcessor=xslTemplate.createProcessor();
return xslProcessor;
}
// Function transformData
// -----------------------------------------------------------------
// This function transforms an XML file with a processor
// Gets an ActiveXObject (loaded XML file) and the processor as parameters
// Returns a result document (as an ActiveXDocument)
function transformData(source,processor){
var resultDoc=new ActiveXObject("MSXML.DOMDocument");
processor.input=source;
processor.output=resultDoc;
processor.transform();
return resultDoc;
}
// Function loadNewXSL
// -----------------------------------------------------------------
// This function calls the other functions - loading XML file
// creating processor, adding a parameter, transforming the XML file
// and placing the result code in the document
// Gets the path to an XSL file and a parameter as paramters
function loadNewXSL(XSLFile, param){
var srcDoc=loadSource("results.xml");
var processor=getProcessor(XSLFile);
processor.addParameter("unit", param);
var rsltDoc=transformData(srcDoc,processor);
target.innerHTML=rsltDoc.xml;
}
</script>
这里用Msxml2.XSLTemplate.5.0加载xml和xsl,然后输出到MSXML.DOMDocument中。
很显然,这个只能在IE上用,在Firefox上有没有实现相应功能的方法能?