//xml是指xml格式的字符串
//xslt是模板的路径
function XSLTToHTML(xml,xslt)
{
var strHTML="";
if (document.implementation && document.implementation.createDocument) { //
// 支持Mozilla浏览器
var xmlDoc;
var xslDoc;
try
{
var parser=new DOMParser();
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc=parser.parseFromString(xml,"text/xml");
}
catch (e) {
alert("error:001");
}
try {
xslDoc = document.implementation.createDocument("", "", null);
xslDoc.async = false;
xslDoc.load(xslt);
}
catch (e) {
alert("error:002");
}
try {
// 定义XSLTProcessor对象
var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xslDoc);
var oResultFragment = xsltProcessor.transformToFragment(xmlDoc, document);
// 将解析过的文本输出到页面
strHTML=oResultFragment;
}
catch (e) {
alert("error:003");
}
}
else if (typeof window.ActiveXObject != 'undefined') { //IE浏览器
var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async = false;
xmldoc.loadXML(xml);
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false
xsl.load(xslt);
strHTML=xmldoc.transformNode(xsl);
}
return strHTML;
}