Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Developer's Guide

Sample ASP Script for XSLT Processor Objects

The following ASP script demonstrates most of the key features of the XSLTProcessor and XSLTemplate objects. It takes the genre parameter from a client-side HTML page and returns a table of all books from the book catalog in the given genre, sorted by title.

The ASP script contains the following functions:

ASP Script (catalog.asp)

<%@LANGUAGE="JavaScript"%>
<%Response.expires=-1;
// catalog.asp
// Sorts books from a given catalog by title, for a given Genre.
function loadSource(sourceName){
    var xmlDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0");
    xmlDoc.async=false;
    xmlDoc.load(Server.mapPath(sourceName));
    return xmlDoc;
    }

function getProcessor(transformName){
    if ("" + Session(transformName) == "undefined"){
        var xslDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0");
        var xslTemplate=new ActiveXObject("Msxml2.XSLTemplate.5.0");
        xslDoc.async=false;
        xslDoc.load(Server.mapPath(transformName));
        xslTemplate.stylesheet=xslDoc;
        xslProcessor=xslTemplate.createProcessor();
        Session(transformName)=xslProcessor;
        }
    else {
        xslProcessor=Session(transformName);
        }
    return xslProcessor;
    }

function transformData(srcDoc,processor){
    processor.input=srcDoc;
    processor.output=Response;
    processor.transform();
    Response.Flush();
    return true;
    }

function main(){
    var srcDoc=loadSource("books.xml");
    var processor=getProcessor("catalogFilter.xsl");

    var genre=Request("genre");
    if(""+genre=="undefined"){
        genre="all";
        }
    else {
        genre=""+genre;
        }           
    processor.addParameter("selected_genre",genre);
    transformData(srcDoc,processor);
    }    

main();    
 %>
Note   The following is an alternative implementation of the transformData() function.
function transformData(srcDoc,processor){
    processor.input=srcDoc;
    processor.transform();
    Response.Write(processor.output);
    return true;
}