The code needed to check the browser’s XSLT support is conceptually simple:
- A small XML file requesting an XSLT style sheet is downloaded from the web
server (see Listing 6).
Listing 6 Browser-check XML file.
<?xml version="1.0" ?> <?xml-stylesheet href="browserCheck.xsl" type="text/xsl"?> <root />
(see Listing 7). Therefore, if the browser processes the
<?xml-stylesheet ?> directive correctly, the XML cookie will be
set. (You can also include the Internet Explorer 5 check here.)
Listing 7 Browser-check XSL style sheet.
The simplest way to integrate the browser-check code with your web pages is to include a hidden IFRAME in every page:
<IFRAME src="browserCheck.xml" style="height: 0px; width: 0px;" />
If you use this solution, make sure that you attend to these details:
- The browser-check XML file and XSL style sheet must have very long expiration times (you might have to use dynamic scripts to set the Expires header), so that they’re not continuously reloaded from the web server.
- The robots.txt file on your web server should prevent search engines from accessing the browser-check XML file; otherwise it will become the highest-ranking page on your web site.
You can also implement a number of other solutions:
- Set an XSL transformation parameter or a special attribute in the XML root element on server transforms, and include the IFRAME code only if the transformation is performed on the server.