var XmlDom=function(){
if (window.ActiveXObject) { // IE
var arrSignatures=[“MSXML2.DOMDocument.5.0”, “MSXML2.DOMDocument.4.0”,
“MSXML2.DOMDocument.3.0”, “MSXML2.DOMDocument”,
“Microsoft.XmlDom”];
for (var i=0; i < arrSignatures.length; i++) {
try {
var oXmlDom=new ActiveXObject(arrSignatures[i]);
return oXmlDom;
} catch (oError) {
//ignore
}
}
throw new Error(“你的系统没有安装 MSXML.”);
} else if(document.implementation.createDocument){ // Firefox
var oXmlDom=document.implementation.createDocument(“”, “”, null);
return oXmlDom;
} else{
throw new Error(“浏览器不支持 XML DOM object.”);
}
}
var transformXSLT=function(_XML,_XSL) {
if (window.Node) {
Node.prototype.transformNode=function(XslDom) {
var oProcessor=new XSLTProcessor();
oProcessor.importStylesheet(XslDom);
var oResultDom=oProcessor.transformToDocument(myXmlDom);
var oSerializer=new XMLSerializer();
var sXml=oSerializer.serializeToString(oResultDom, “text/xml”);
return sXml;
}
}
var myXmlDom=new XmlDom();
myXmlDom.async=false;
var myXslDom=new XmlDom();
myXslDom.async=false;
myXmlDom.load(_XML);
myXslDom.load(_XSL);
var sResult=myXmlDom.transformNode(myXslDom);
if(window.ActiveXObject){
if(myXmlDom.parseError.errorCode !=0){
var sError=myXmlDom.parseError;
var txt=””;
txt +=”错误代码: “;
txt +=sError.errorCode;
txt +=”错误原因: “;
txt +=sError.reason;
txt +=”错误行号: “;
txt +=sError.line;
document.write(txt);
}else{
document.write(sResult);
}
} else if(document.implementation.createDocument){
var oSerializer=new XMLSerializer();
var sXmlDom=oSerializer.serializeToString(myXmlDom, “text/xml”);
var oParser=new DOMParser();
var oXmlDom=oParser.parseFromString(sXmlDom,”text/xml”);
if (oXmlDom.documentElement.tagName==”parsererror”) {
var oXmlSerializer=new XMLSerializer();
var sXmlError=oXmlSerializer.serializeToString(oXmlDom);
alert(sXmlError);
} else {
document.write(sResult);
}
}
}
var TransformBinder=function(XML,XSL) {
this.XML=XML;
this.XSL=XSL;
}
TransformBinder.prototype.registerAction=function(handlers) {
this.handlers=handlers;
}
TransformBinder.prototype.bind=function() {
var _this=this;
this.handlers(_this.XML,_this.XSL);
}