| 发表于:2008-02-27 16:59:064楼 得分:0 |
调用xml文件和xslt文件生成html用js我已经实现.例子如下: <html> <head> <script> function loadxmldoc(fname) { var xmldoc; // code for ie if (window.activexobject) { xmldoc=new activexobject("microsoft.xmldom"); } // code for mozilla, firefox, opera, etc. else if (document.implementation && document.implementation.createdocument) { xmldoc=document.implementation.createdocument("","",null); } else { alert('your browser cannot handle this script'); } xmldoc.async=false; xmldoc.load(fname); return(xmldoc); } function displayresult() { xml=loadxmldoc("test.xml"); xsl=loadxmldoc("test.xslt"); // code for ie // document.getelementbyid("example").innerhtml=ex; if (window.activexobject) { ex=xml.transformnode(xsl); document.getelementbyid("example").innerhtml=ex; } // code for mozilla, firefox, opera, etc. else if (document.implementation && document.implementation.createdocument) { xsltprocessor=new xsltprocessor(); xsltprocessor.importstylesheet(xsl); resultdocument = xsltprocessor.transformtofragment(xml,document); document.getelementbyid("example").appendchild(resultdocument); } } </script> </head> <body onload="displayresult();"> <div id="example"> </div> </body> </html> 不过我要实现的跟这个还不太一样.正在思考中...我要从form text中取得xml内容与指定xslt一起再生成html...不知哪位高手有做过哦... | | |
|