Latest web development tutorials

XSLT on the server side

Because not all browsers support XSLT, another solution is to complete the conversion to XML on the server of XHTML.

Cross-browser solution

In the previous section, we explain how to use XSLT through the browser to complete the XML to XHTML conversion. We created some use an XML parser to convert the JavaScript. JavaScript solution does not work in no XML parser browser.

To make XML data applicable to any type of browser, we must be on the server for XML document conversion, and then sent back to the browser as XHMTL.

This is another advantage of XSLT. One of the design goals for XSLT was to make data on the server to convert from one format to another format as possible, to all types of browsers returned readable data.

XML documents and XSLT files

Look at this in the previous section has shown off an XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>

View the XML file .

And accompanying XSL style sheet:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"

<xsl:template match="/">
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
<xsl:for-each select="catalog/cd">
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>


See XSL file .

Please note, the XML file does not contain a reference to the XSL file.

IMPORTANT: The above sentence means, XML files can use several different XSL stylesheets to convert.

On the server convert XML to XHTML

It is used on the server to XML files into XHTML source code:

'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false

'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false

'Transform file

Tip: If you do not know how to write ASP, you can study our ASP tutorial .

First block of code creates an instance of Microsoft's XML parser (XMLDOM) and the XML file into memory. The second paragraph of code creates another instance of the parser, and to this XSL file into memory. The last line of code using the XSL document conversion XML document, and sends the result as XHTML to your browser. Great!

How it works .