George, here's a function I use regularly to run XSL transformations with parameters:
Code:
Sub DoXslt(sXml, sFileXslt, dctParams)
'==============================================================
' Function : DoXslt
' Purpose : performs an XSLT transformation with parameters
' Author : Phil Griffiths
' Parameters : sXml - the xml string
' : sFileXslt - relative filename of XSLT
' : dctParams - Scripting.Dictionary containing param name/value pairs
' Globals : Response object
' Return : None - transformation result written to Response
' Mods : PG 16/4/2002 - Initial Version
'==============================================================
Dim domXml, domXslt, xslt, xslProc, vKey
If Len(sXml) > 0 And Len(sFileXslt) > 0 Then
Set domXml = LoadXmlIntoDom(cProgIdMsxml, sXml)
Set domXslt = LoadXmlFileIntoDom(cProgIdMsxmlFreeThread, Server.MapPath(sFileXslt))
Set xslt = Server.CreateObject(cProgIdXslTemplate)
With xslt
Set .stylesheet = domXslt
Set xslProc = .createProcessor()
End With
With xslProc
.input = domXml
.output = Response
If Not dctParams Is Nothing Then
For Each vKey in dctParams
Call .addParameter(vKey, dctParams(vKey))
Next
End If
.Transform
End With
Set xslProc = Nothing
Set xslt = Nothing
Set domXml = Nothing
Set domXslt = Nothing
End If
End Sub
You'll need these useful supporting functions and constants too
Code:
Const cProgIdMsxml = "MSXML2.DOMDocument.4.0"
Const cProgIdMsxmlFreeThread = "MSXML2.FreeThreadedDOMDocument.4.0"
Const cProgIdXslTemplate = "MSXML2.XSLTemplate.4.0"
Const cProgIdDictionary = "Scripting.Dictionary"
Function LoadXmlIntoDom(sProgId, sXml)
'==============================================================
' Function : LoadXmlIntoDom
' Purpose : loads an xml string into a DOM object
' Author : Phil Griffiths
' Parameters : sProgId - of the XML DOM object to create
' : sXml - the xml string
' Globals : None
' Return : object specified by sProgId
' Mods : PG 15/4/2002 - Initial Version
'==============================================================
Set LoadXmlIntoDOM = Server.CreateObject(sProgId)
LoadXmlIntoDOM.async = False
Call LoadXmlIntoDOM.loadXML(sXml)
Call LoadXmlIntoDOM.setProperty("SelectionLanguage", "XPath")
End Function
Function LoadXmlFileIntoDom(sProgId, sXmlFilePath)
'==============================================================
' Function : LoadXmlIntoDom
' Purpose : loads an xml file into a DOM object
' Author : Phil Griffiths
' Parameters : sProgId - of the XML DOM object to create
' : sXmlFilePath - the path of the xml file
' Globals : None
' Return : object specified by sProgId
' Mods : PG 15/4/2002 - Initial Version
'==============================================================
Set LoadXmlFileIntoDOM = Server.CreateObject(sProgId)
LoadXmlFileIntoDOM.async = False
Call LoadXmlFileIntoDOM.load(sXmlFilePath)
Call LoadXmlFileIntoDOM.setProperty("SelectionLanguage", "XPath")
End Function
If you put these functions into an include file, then all you need in your asp is something like this to run any transformation with parameters
Code:
Dim dctParams
Set dctParams = Server.CreateObject(cProgIdDictionary)
With dctParams
.Add "ParamName1", "ParamValue1"
.Add "ParamName2", "ParamValue2"
' etc...
End With
Call DoXslt(sXmlData, "xslt/thefile.xsl", dctParams)
Set dctParams = Nothing
hth
Phil