Create pages from XML on the fly

Looking for something to ease the pain of creating pages from XML on the fly? This code allows the use of filtering/sorting/paging etc. by passing parameters from the host ASP page's querystring to the XSL Template that is formatting the XML.
'ASP Plugin to allow parameterized use of XSL Templates on XML Data.
' oXML represents the XML file to be changed
' oXSL represents the XSL template being used.  This file contains
' the majority of the logic for viewing/sorting/filtering records.
' THIS PLUGIN REQUIRES MSXML4.0 to be installed on the server.

'                       SAMPLE CODE FOLLOWS   

dim oXML,oXSL           'Initiate variables for XML/XSL docs
dim ParamNames(1)       'Initiate the Array to hold number of Querystring Variables
dim Params(1)           'Initiate the Array to hold number of Querystring Variables

'Assign Parameter Names to ParamNames Array
ParamNames(0) = "name of first XSL param"
'Assign Parameter Values to Params Array
Params(0) = Cstr(Request("Querystring1"))

'Instantiate XML and XSL objects
set oXML = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.4.0")
set oXSL = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.4.0")

'Set properties on XML/XSL objects

'Load documents into memory

'Run Parser functions to output to screen
ParseXML oXML,oXSL,ParamNames,Params

'                       SAMPLE CODE ENDS

function ParseXML(XML,XSL,ParamNames(),Params())
        'Declare variables.
        dim oXML, oXSL, oXslt, oNode, oProc

        'Instantiate objects for XML/XSL files
        set oXML = XML
        set oXSL = XSL

        'Create an XSLT processing object
        set oXslt = Server.CreateObject("Msxml2.XSLTemplate.4.0")

        'Assign the in-memory XSL file to it.
        oXslt.stylesheet = oXSL

        'Instantiate the XSLT processor object
        set oProc = oXslt.createProcessor

        'Assign the in-memory XML file as the input file.
        oProc.input = oXML

        'Set all necessary parameters in the XSL Template.
        for i = 0 to (UBound(ParamNames) -1)
        oProc.addParameter ParamNames(i), Params(i)

        'Process/Transform the document and output to screen.
        oProc.output = Response
end function

This was first published in January 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.