So how does XSL fit into the big picture? To produce the final HTML pages for your website's visitors, you need to apply an XSL stylesheet to your XML data source. The actual transformation can be performed either by your web server or by the client's browser. The final output can be a full HTML page or only a portion of it, used on separate pages.
Both the server-side and the client-side approach have their benefits and disadvantages. Server-side transformations let you process XML documents either from your server or from elsewhere, on the Internet. The server performs the actual work, which produces HTML output that any browser can load, no matter how old or new. On the other hand, to perform a server-side XSL transformation, you must have a properly configured application server, with support for XML and XSL. Not all hosting servers come prepared for this. That is why I will explain how to install and configure the necessary XML/XSL libraries for PHP servers in one of my next articles. The soon-to-be-released Dreamweaver 8 supports XSL transformations for ColdFusion, ASP, ASP.NET, and PHP pages.
The server-side transformation workflow is described in the diagram below:
Figure 1. The server-side XSL transformation workflow
Note that the XML document does not need to be located on the web server. It can also be placed on a remote website, in which case it will be loaded on your server upon request.
In a client-side transformation, the client's browser does all the work. The downside of this approach is that not all browsers have XML/XSL support, so some of your clients might not be able to see your pages. For a list of modern browsers that have XML/XSL features, visit this page on the W3 Consortium website. In addition, when using the client-side approach, you are restricted to processing local XML files only. If you need, for instance, to consume a RSS feed from another website, you have to download a copy of it and then upload it to your server. If the original RSS file on the remote website changes, you must download the file again, and re-post it to your web server.
To indicate to the browser which XSL stylesheet must be used to process the XML document, you must include the following declaration in the XML file, right after the XML declaration:
<?xml-stylesheet type="text/xsl" href="company.xsl"?>
The href attribute specifies the path to the XSL stylesheet that must be used. The mechanism resembles the way an external CSS stylesheet is referred at the beginning of an HTML page. The following diagram explains the client-side workflow for XSL transformations:
Figure 2. The client-side XSL transformation workflow