ThePlace

Home ] Search ] Resources ] Site Map ] Contact Me ]
Dave's Information Technology Resource

Up ] Server XML Demo ]

XSL and Transformation ] [ XSL and the Server ] XSL and the Client ] XSL Functions ]

--- XSL and the Server ---

XSL - On the Server

A Cross Browser Solution

bulletTo make our XML data available to all kinds of browsers (some do not support XML), we have to transform the XML document on the SERVER and send it as pure HTML to the BROWSER.
bulletThat's another the beauty of XSL. One of the design goals for XSL was to make it possible to transform data from one format to another on a server, returning readable data to all kinds of future browsers.
bulletXSL transformation on the server is bound to be a major part of the Internet Information Server work tasks in the future, as we will se a growth in the specialized browser marked (think: Braille, Speaking Web, Web Printers, Handheld PCs, Mobile Phones .....).

The XML file and the XSL file

Take a new look at the following XML  (or open it with IE5):

<?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>
.
.
.

 

bulletAnd at the companying XSL stylesheet (or open it with IE5):

 

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
  <html>
  <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>
  </html>
</xsl:template>
</xsl:stylesheet>

 

bulletThe syntax of the above XSL document was explained in the previous section, so it will not be explained here. But be sure to notice that the XML file does not have a reference to the XSL file, and the XSL file does not have a reference to the XML file.
bulletIMPORTANT: The above sentence indicates that an XML file on the server could be transformed using many different XSL files.

 

Transforming XML to HTML on the Server

bulletHere is the simple source code needed transform the XML file to HTML on the server via ASP:

 

<%
'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))
%>

 

bulletThe first block of code creates an instance of the Microsoft XML parser (XMLDOM), and loads the XML file into memory. 
bulletThe second block of code creates another instance of the parser and loads the XSL document into memory
bulletThe last line of code transforms the XML document using the XSL document, and returns the result to the browser.
bulletTry this code.
bulletNote: the above code assumes that the server supports the XML DOM and associated ASP technology.

 

Home ] Up ] Computer Architecture ] Programming Bootcamp ] Database Bootcamp ] Visual BasicS ] Web Basics ] Web Multimedia ] Web Programming ] Advanced Web Topics ] Developing Web Sites ] XML Technology ] Web Glossary ]

Copyright © 1999 - 2005 
ThePlace - Written and Sponsored by Dave Hillman