Create pages from XML on the fly

Looking for something to ease the pain of creating 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
oXML.preserveWhiteSpace=true
oXSL.preserveWhiteSpace=true

'Load documents into memory
oXML.load(Server.MapPath("sample.xml"))
oXSL.load(Server.MapPath("sample.xsl"))

'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)
        next

        'Process/Transform the document and output to screen.
        oProc.output = Response
        oProc.transform
end function
This was first published in January 2005

Dig deeper on Win Development Resources

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close