|
||
| Inside Technique : Building Smart Pages with ASP, XML and XSL : Applying XSL on the Server The builk of the hard work in our ASP script is handled by the TransformDocument
and OutputDocument functions. We are going to start with the simpler OutputDocument function.
Given an XML file, this function sets the document type to "text/xml" so the client knows
it is receiving XML, opens the document, and finally sends it to the client.
An alternative to manually retrieving the file is to redirect the user to the XML file. We chose not to redirect so to keep a single URL. When you redirect, you are actually returning a code that tells the client to request a different page. This requires an additional round-trip and also exposes an alternative URL to the user which would only be valid in Internet Explorer 5.0 (or XML/ XSL enabled browsers). The next function is the TransformDocument function. This function performs the same work
IE5 provides but on the server. This function takes an XML
and XSL file name. The XML and XSL file are loaded in memory on the server and then
the XSL file is applied to the HTML to transform it into HTML. The generated HTML is
then returned to the client. In this case, the client has no knowledge
that your pages originated in XML.
If an error occurs, we call the reportParseError or reportRunTimeError functions. Since these are fairly simple functions that just output the error, we do not cover them here (you can view them by downloading the sample files). Before running off and deploying this, if you have a heavily trafficked site, you should be aware of the following performance consideration: This solution does all the transformations immediately upon request. Since the document's and transformations do not dynamically change, a better approach is to build a document management system that performs and caches all the transformations on your server. This avoids the cost of having to load, parse, and transform the document on every request. In our next article in this series, we are going to extend our demonstration with additional interactivy. You will see how to provide an article summary and the detailed article from the same URL and same XML document by applying different transformations. Page 1:Building Smart Pages with ASP, XML and XSL © 1997-2000 InsideDHTML.com, LLC. All rights reserved. |