Original article: JanEgilRefsnes translation: Ajie 4: XSL --- implement it on the server 1. compatible with all browsers in the previous chapter, we first introduced the ability to use JavaScript to call the XMLparser (parsing software) of the browser to convert XML documents. But this plan is based on
Original: Jan Egil Refsnes
IV. XSL --- implementation on the server
1. compatible with all browsers
In the previous chapter, we first introduced how to use JavaScript to call the XML parser (parsing software) of the browser to convert XML documents. However, this plan still has a title: if the browser does not have XML
What should I do with the parser plug-in? (Note: XML parser is included in IE5)
In order to make our XML data accurately displayed by all browsers, we have to convert XML into pure HTML code on the server side and then output it to the browser.
This is another benefit of using XSL. Converting one pattern into another pattern on the server side is also one of the design objectives of XSL.
Similarly, conversion will become an important task for future server segments.
2. a specific instance
The following is part of the code in the above-mentioned XML document (cd_catalog.xml) example:
Empire Burlesque
Bob Dylan
USA
Columbia
10.90
1985
...
The complete XSL file (cd_catalog.xsl) is as follows ):
The following is the original code for converting an XML file to an HTML file on the server:
<%
'Load the XML
Set xml = Server. CreateObject ("Microsoft. XMLDOM ")
Xml. async = false
Xml. load (Server. MapPath ("cd_catalog.xml "))
'Load the XSL
Set xsl = Server. CreateObject ("Microsoft. XMLDOM ")
Xsl. async = false
Xsl. load (Server. MapPath ("cd_catalog.xsl "))
Response. Write (xml. transformNode (xsl ))
%>
Note: The example here uses an ASP file written in VBScript. If you do not know ASP or VBScript, you are advised to browse related books. (Of course, you can also write server programs in other languages)
The first code creates an object parsed by Microsoft Parser (XMLDOM) and reads the XML file into the memory. The second code creates another object and imports it into the XSL document; the last line of code converts the XML document into an XSL document and outputs the result to an HTML file.