- Introduction
- The Framework
- The Solution
- Browser Checking
- Static XML Files
- Summary
Static XML Files
The static XML files residing on your server must be handled in three different ways:
- If the XML file contains the <?xml-stylesheet ?> directive, it can be sent to XSLT-capable browsers directly.
- If the desired XSLT style sheet has to be inserted into the XML data, the file has to be read and processed by a server-side script and sent to XSLT-capable browsers as an XML data stream.
- For all other clients (including search engines), the XSLT transformation is performed on the server.
Due to the varying client requirements, the static XML files cannot be served directly, but instead have to be processed by a server-side script accepting the filename and XSLT style sheet as input parameters. The URL to download a static XML file would thus be similar to this:
sendXML.asp?file=filename&xsl=stylesheet
The easiest way to implement this script is to load the XML data from the source file into a DOM tree structure and output the result using the OutputXMLResponse function described earlier. A simplistic implementation of this script (with no error checking) is included in Listing 8. Alternatively, you can implement the same functionality by reading the source XML file and inserting the <?xml-stylesheet ?> directive as a string in the output stream.
Listing 8 Return XML or HTML response from a static XML file.
Set XDoc = Server.CreateObject("MSXML2.DOMDocument.5.0") XDoc.Load(Server.MapPath(Request("file"))) xmlStyleSheet = Null If Request("xsl") <> "" Then xmlStyleSheet = Request("xsl") OutputXMLResponse XDoc,xmlStyleSheet
For XML files already containing the <?xml-stylesheet ?> directive (or whenever sendXML.asp is called without the style sheet parameter), you can implement another optimization technique: Rather than returning the raw XML data, the server-side script can return the 301 (Moved Permanently) HTTP status code, which ensures that the browser won’t call the server-side script in the future but instead will fetch the XML file directly.