Today, we spend a day receiving XML data and formatting XSL-style sheets. Of course, this work is easy on IE. But when I moved to Firefox, everything was not that good. :))
The cross-browser function of scripts must be implemented. Before dinner in the morning, I found a conflict between my own handwriting and the use of open-source frameworks. Finally, I used to rewrite the materials.CodeSmall.
The following is the encapsulated JS function, which can be used on Firefox and IE temporarily. The test is only a small scope. This function is usedProgramSo I wrote this ......
/*
XML: a connection or file that can be provided to XML data.
XSL: Join of a style sheet or style sheet
Div: the ID of the layer-Div
Result: The XML parsing result of the XSL file is written into the div.
*/
Function showxml (XML, XSL, Div ){
If (Window. activexobject ){
Iexml (XML, XSL, Div );
}
// Para funcionar no Mozilla/Firefox
Else If (Window. XMLHttpRequest ){
Firexml (XML, XSL, Div );
}
}
Function iexml (XML, XSL, Div ){
VaR objexml;
VaR objexsl;
VaR objexml = New Activexobject ( " Microsoft. xmldom " );
Objexml. async = False ;
Objexml. Load (XML );
VaR objexsl = New Activexobject ( " Microsoft. xmldom " );
Objexsl. async = False ;
Objexsl. Load (XSL );
VaR thediv = Document. getelementbyid (DIV );
Thediv. innerhtml = Objexml. transformnode (objexsl );
}
Function firexml (XML, XSL, Div ){
VaR objexsltprocessor;
VaR objexmldoc;
VaR objexslt;
VaR objexml;
VaR objexsl;
Objexsltprocessor= New Effectprocessor ();
Objexsl = New XMLHttpRequest ();
Objexsl. Open ( " Get " , XSL, False );
Objexsl. Send ( Null );
Objexslt = Objexsl. responsexml;
Objexsltprocessor. importstylesheet (objexslt );
Objexml = New XMLHttpRequest ();
Objexml. Open ( " Get " , XML, True );
Objexml. Send ( Null );
Objexmldoc = ( New Domparser (). parsefromstring (objexml. responsetext, " Text/XML " );
VaR TVs = Objexsltprocessor. transformtofragment (objexmldoc, document );
VaR thediv = Document. getelementbyid (DIV );
Div. innerhtml = "" ;
Thediv. appendchild (TVS );
}