Frog recommendation: Use the XSLT style sheet on the client to convert XML documents

Source: Internet
Author: User
Tags file url xsl xslt

Frog recommendation: Use the XSLT style sheet on the client to convert XML documents

I have not provided the source XML document and the two XSLT style sheets. You can write them yourself.

<HTML>
<Head>
<Style type = "text/CSS">
Body {font-family: tahoma, verdana, Arial, sans-serif; font-size: 14px}
. Head {font-family: tahoma, verdana, Arial, sans-serif; font-size: 18px; font-weight: bold}
</Style>

<Script language = "jscript">
<! --

Function transformfiles (strstylesheetname ){

// Obtain the data layer that displays the Conversion Result
VaR objresults = Document. All ['divresult'];

// Create two objects
VaR objxml = new activexobject ('msxml2. domdocument.3.0 ');
VaR objxsl = new activexobject ('msxml2. domdocument.3.0 ');

// Set two attributes
Objxml. validateonparse = true;
Objxsl. validateonparse = true;

// Load the XML document and check for errors
Objxml. Load ('tables _ data. xml ');
If (objxml. parseerror. errorcode! = 0 ){
// If error 9 is returned, the operation is terminated and an error is displayed.
Objresults. innerhtml = showerror (objxml)
Return false;
}

// Load the style sheet and check for errors
Objxsl. Load (strstylesheetname );
If (objxsl. parseerror. errorcode! = 0 ){
// If an error occurs, the system displays the error and terminates the program.
Objresults. innerhtml = showerror (objxsl)
Return false;
}

// If no error exists, perform the conversion.
Strresult = objxml. transformnode (objxsl );

// Display the conversion result at the display result layer.
Objresults. innerhtml = strresult;
Return true;
}

Function showerror (objdocument ){
// Create an error message
VaR strerror = new string;
Strerror = 'invalidxml file! <Br/>'
+ 'File URL: '+ objdocument. parseerror. url +' <br/>'
+ 'Line No.: '+ objdocument. parseerror. Line +' <br/>'
+ 'Character: '+ objdocument. parseerror. linepos +' <br/>'
+ 'File position: '+ objdocument. parseerror. filepos +' <br/>'
+ 'Source text: '+ objdocument. parseerror. srctext +' <br/>'
+ 'Error code: '+ objdocument. parseerror. errorcode +' <br/>'
+ 'Description: '+ objdocument. parseerror. Reason
Return strerror;
}

// -->
</SCRIPT>

</Head>
<Body onload = "transformfiles ('tables _ list. XSL ')">
<P> <SPAN class = "head"> use the XSLT style sheet on the client to convert XML documents </span> </P>
View Details & nbsp; <button onclick = "transformfiles ('tables _ catalog. XSL ')"> contents </button>
& Nbsp; or & nbsp; <button onclick = "transformfiles ('tables _ list. XSL ')"> simple list </button>
<HR/>

<! -- Insert XML and XSLT conversion results in this layer -->
<Div id = "divresults"> </div>

</Body>
</Html>

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.