␡
- Introduction
- The Framework
- The Solution
- Browser Checking
- Static XML Files
- Summary
Like this article? We recommend
Browser Checking
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 />
- The resulting HTML markup contains JavaScript code to set the XML cookie
(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.
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <xsl:template match="/"> <html> <head><script src="xmlPresentation.js" type="text/javascript"><!-- contains xSetCookie --></script></head> <body onload="xSetCookie(’XML’,’1’)">Cookie set</body> </html> </xsl:template> </xsl:stylesheet>
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.
- Check for the presence of an XML cookie with JavaScript, and dynamically generate the IFRAME on the browser if the XML cookie is not set.