Receives XML data and uses the XSL style sheet for formatting

Source: Internet
Author: User

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 );
}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.