The purpose of this ISAPI filter is to be able to serve up XSL styled documents for browser clients that do not natively support XSL formatting (namely, any version of IE other than IE5). The filter also provides caching of the XSL style sheets in memory for improved performance on the server.
It is an MFC ISAPI Wizard-based application that also serves as a good sample application for those wanting to build their own custom XML ISAPI filters.
Copy the xmlisapi.dll to your machine (you can put it in the %SystemRoot%\SYSTEM32\INETSRV directory if you want - but it doesn't have to go there). Then from the Internet Service Manager console open the properties dialog for the Default Web Site, select the Home Directory tab, click the Configuration... button, and add a new Application Mapping with the the xmlisapi.dll as the executable, the extension ".xml" and with the method exclusions PUT,POST,DELETE. Also deselect the Script engine check box. You will also need to change the Permissions on the Home Directory from Script to Execute so the ISAPI filter is allowed to execute over on XML document in your website. Then it should be live. The next GET request for a .xml document on your website will go through the ISAPI filter.
The XML ISAPI filter checks the client browser type. If it finds anything other than MSIE 5.x it will perform the XSL transform on the server. (Note: there was also a bad bug in the XML MimeViewer in the IE5.0 version that shipped in NT Beta3 -- therefore it also looks for MSIE 5.0 on Windows NT 5.0 and does server side processing in this case also. Newer versions of Windows NT 5.0 contain MSIE 5.1 and in this case the ISAPI filter lets the client do the XSL processing).
If the ISAPI filter decides to do server side processing it loads the first 4096 bytes of the XML file and sniffs for the first <?xml:stylesheet or <?xml-stylesheet tag. (Note: If this PI does not specify text/xsl then it will not do server side processing - in other words, server-side CSS is not supported).
The ISAPI filter looks for either the href attribute of a new extended attribute in called server-href. If this is present it uses the stylesheet pointed to by that attribute for the server-side XSL processing. This allows you to have custom stylesheets for those clients that do not support client side XSL. For example:
<?xml-stylesheet type="text/xsl" href="advanced.xsl" server-href="ie4.xsl"?>
The caching algorithm is very simple. Each hit it loads the WIN32_FIND_DATA and checks the ftLastWriteTime and the nFileSizeLow fields. If either of those have changed it reloads the stylesheet. Also, to avoid using too much memory and problems with fragmentation on the server over time, after every 10000 hits it clears the cache completely.
The ISAPI filter was generated by the MFC ISAPI Wizard and so the following files marked with an asterix(*) are boiler plate files straight from that wizard:
Filename | Purpose |
---|---|
Resource.h(*) | Define constances used in resource files |
StdAfx.cpp(*) | Standard include files. |
StdAfx.h(*) | Standard include files - used to build precompiled headers. |
xmlisapi.cpp | The real meat of the program. |
xmlisapi.def(*) | Defines DLL entry points required by ISAPI filters. |
xmlisapi.dsp(*) | The Visual C++ 6.0 project file for building the DLL |
xmlisapi.h | Declares the classes that make up this application (CXslCache, CXmlHttpStream, and CXmlIsapiExtension. |
xmlisapi.rc(*) | Resources - mostly just version information |
xmlisapi.rc2(*) | More resource - this is basically empty boiler plate. |