开发者

XML cross-browser support

I need help getting the file to run in Firefox: I have tried adapting scripts so that my file runs in both IE and Firefox but so far it still only works in IE. (The file can be tested at http://www.eyle.org/crosstest.html - simply type the word Mike in the text box using IE (doesn't work in Firefox).The HTML document is:

<!DOCTYPE html PUBLIC 
     "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript">
        var xmlDoc;
        //loads xml using either IE or firefox
        function loadXmlDoc()
        {
            //test for IE
            if(window.ActiveXObject)
            {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async = false;
                xmlDoc.load("books2.xml");
            }

            //test for Firefox
            else if(document.implementation && document.implementation.createDocument)
            {
                xmlDoc = document.implementation.createDocument("","",null);
                xmlDoc.load("books2.xml");
            }
            //if neither
            else
  开发者_StackOverflow中文版          {
                document.write("xml file did not load");
            }
        }

        //window.onload = loadXmlDoc();
        var subject;
        //getDetails adds value of txtField to var subject in outputgroup(subject)
        function getDetails()
        {
            //either this or window.onload = loadXmlDoc is needed
            loadXmlDoc();
            var subject = document.getElementById("txtField1").value;
            function outputgroup(subject) 
            {
                var xslt = new ActiveXObject("Msxml2.XSLTemplate");
                var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
                var xslProc;
                xslDoc.async = false;
                xslDoc.resolveExternals = false;
                xslDoc.load("contains3books.xsl");
                xslt.stylesheet = xslDoc;
                xslProc = xslt.createProcessor();
                xslProc.input = xmlDoc;
                xslProc.addParameter("subj", subject);
                xslProc.transform();
                document.write(xslProc.output);
            }
            outputgroup(subject);
        }

    </script>
</head>

<body>
    <input type="text" id="txtField1">
    <input type="submit" onClick="getDetails(); return false">
</body>
</html>

The file includes books2.xml and contains3books.xsl (I have put the code for these files at ...ww.eyle.org/books2.xml ...ww.eyle.org/contains3books.xsl) (NB: replace ...ww. with http: // www)


ActiveX is mechanism which helps IE loading other apps/controls in browser itself. It is meant only for IE and no other browser supports it.

Visit the following site for more info:

http://www.reloco.com.ar/mozilla/compat.html

http://support.mozilla.com/en-US/kb/ActiveX


Your outputgroup function uses an ActiveXObject creation to create an xslt this is IE specific

For mozilla use XSLTProcessor();

eg for firefox

var processor = new XSLTProcessor(); //create object 

xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.load("books2.xml");

xslDoc.load("contains3books.xsl"); 
xslt.stylesheet = xslDoc;
processor.importStylesheet(xslDoc);//import a stylesheet 

var output = processor.transformToFragment(xmlDoc);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜