Problem solve Get help with specific problems with your technologies, process and projects.

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

'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

Dig Deeper on Win Development Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.