<script type="text/javascript">
loadXML = function(fileRoute){
xmlDoc=null;
if (window.ActiveXObject){
xmlDoc = new ActiveXObject('Msxml2.DOMDocument'); xmlDoc.async=false; xmlDoc.load(fileRoute);
}
else if (document.implementation && document.implementation.createDocument){
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET",fileRoute,false);
xmlhttp.send(null);
xmlDoc = xmlhttp.responseXML; //返回document對象
}
else {xmlDoc=null;}
return xmlDoc;
}
var Browser={};
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
var xmlObj=loadXML("cdcatalog.xml");
var xslObj =loadXML("cdcatalog.xsl");
if(Browser.isMozilla==true){
//firefox沒有實現xml.transformNode,添加transformNode方法。
Node.prototype.transformNode = function (oXslDom) {
var oProcessor = new XSLTProcessor();
oProcessor.importStylesheet(oXslDom);
var oResultDom = oProcessor.transformToDocument(this);
var xmls = new XMLSerializer();
return xmls.serializeToString(oResultDom);
}
}
document.write(xmlObj.transformNode(xslObj));
</script>
查看檔案 cdcatalog.xsl cdcatalog.xml