An XSL Concise tutorial (4) Implementation on the server side _xml/rss

Source: Internet
Author: User
Tags xml parser xsl xsl file
Original: A Egil refsnes translation: Atzie

IV: The implementation of XSL---on the server side


1. Compatible with all browsers

In the previous chapter we described the XML parser (parsing software) that can be used to invoke the browser through JavaScript to transform XML documents. But the solution still has a problem: if the browser doesn't have XML
What about the parser plugin? (Note: IE5 with XML parser)

In order for our XML data to be displayed correctly by all browsers, we had to convert the XML to pure HTML code on the server side and then output it to the browser.

This is another benefit of using XSL. Converting one format to another on the server side is also one of the design goals of XSL.

In the same way, conversion work will be the main work of future server segments.


2. A concrete example

Here is some of the code for an example of an XML document (Cd_catalog.xml) that we mentioned above:

<?xml version= "1.0" encoding= "Iso8859-1"?>

<CATALOG>

<CD>

<title>empire burlesque</title>

<artist>bob dylan</artist>

<COUNTRY>USA</COUNTRY>

<COMPANY>Columbia</COMPANY>

<PRICE>10.90</PRICE>

<YEAR>1985</YEAR>

</CD>

.

.

.


The following is the complete XSL file (cd_catalog.xsl):


<?xml version= ' 1.0 '?>

<xsl:stylesheet xmlns:xsl= "Http://www.w3.org/TR/WD-xsl" >

<xsl:template match= "/" >


<body>

<table border= "2" bgcolor= "Yellow" >

<tr>

<th>Title</th>

<th>Artist</th>

</tr>

<xsl:for-each select= "CATALOG/CD" >

<tr>

<td><xsl:value-of select= "TITLE"/></td>

<td><xsl:value-of select= "ARTIST"/></td>

</tr>

</xsl:for-each>

</table>

</body>


</xsl:template>

</xsl:stylesheet>


The following is the original code that converts an XML file to an HTML file on the server side:


<%

' 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 examples we use here are ASP files, written in VBScript. If you do not understand ASP or VBScript, suggest reading about books. (Of course, you can also write server-side programs in other languages)


The first code creates a Microsoft Parser (XMLDOM) Resolved object and reads the XML document into memory, the second code creates another object and imports the XSL document, and the last line of code converts the XML document into an XSL document and outputs the results to an HTML file.

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.