[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] ASP and MSXML AddParameter


Subject: Re: [xsl] ASP and MSXML AddParameter
From: "Marcus Andersson" <marcan@xxxxxxx>
Date: Mon, 7 Jul 2003 23:55:45 +0200

You shouldn't use objXML.transformNode(...) if you want to use parameters (as you seems to have realized).

I have a code suggestion where I also assume you are using at least MSXML3 (a warning though, I usually do this in jscript and not in vbscript so be careful around the parenthesis, dims and stuff...). The code is completely untested and is a conversion of some jscript code that does similar stuff. So here it goes...

Function loadXMLFile(strXMLFile, strXSLFile, strOptionalParam1)

  'Declare local variables
  Dim objXML
  Dim objXSL
  Dim xslTemplate, xslProc

  'Instantiate the XMLDOM Object that will hold the XML file.
  set objXML = Server.CreateObject("Msxml2.DOMDocument")

  'Turn off asyncronous file loading.
  objXML.async = false

  'Load the XML file.
  objXML.load(strXMLFile)  
  
  if len(strXSLFile) then
    ' FreeThreaded documents are used when creating processors
    set objXSL = Server.CreateObject("Msxml2.FreeThreadedDOMDocument")    
    'Turn off asyncronous file loading.
    objXSL.async = false

    'Load the XSL file.
    objXSL.load(strXSLFile)

    ' Create a template made of your XSL file. Much needed for the creation of your processor.
    set xslTemplate = Server.CreateObject("Msxml2.XSLTemplate")  
    ' Setting the actual XSL document in the template
    xslTemplate.stylesheet = objXSL
    ' Compile your stylesheet into a processor
    set xslProc = xslTemplate.createProcessor()
    
    if len(strOptionalParam1) then
       xslProc.addParameter "param1", strOptionalParam1  ' Add your parameter
    end if
    xslProc.input = objXML  ' The xml input here is actually the xml you want to transform
    xslProc.transform()  ' Do the transformation
    Response.Write(xslProc.output)  ' Print the transformed result

  else

    Response.Write (objXML.transformNode(objXML))

 end if


if Err.Number then
ErrorReportingRoutine()
end if
End Function


The processor can also be cached if you want to do this over and over. Just make sure you reset it in between

cheers

/Marcus
----- Original Message ----- 
From: "Jay Zeiger" <jzeiger@xxxxxxxxxxxx>
To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, July 07, 2003 11:18 PM
Subject: [xsl] ASP and MSXML AddParameter


> I have coded ASP (thanks to internet.com) so that I can display XML/XSL
> files, but I need to add the "AddParameter" method. I have read some older
> posts here, but I can't quite figure out how to do this. If I wanted to add
> a parameter named "param1", I think I need something like:
> 
> 
> if len(strOptionalParam1) then
> Set xslProc = xslt.createProcessor()
> xslProc.input = xmlDoc    ' >>>>>>---- what is this xmlDoc suppose to refer
> to??????
> xslProc.addParameter "param1", strOptionalParam1
> xslProc.Transform
> end if
> 
> 
> 
> '
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> +++++++++++++++
> ' + But, how is this properly integrated into my function (assume that
> strOptionalParam1
> ' + contains the param1 value) ????????????????????
> '
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ++++++++++++++++
> 
> Function loadXMLFile(strXMLFile, strXSLFile, strOptionalParam1)
> 
> 'Declare local variables
>   Dim objXML
>   Dim objXSL
> Dim xslProc
> 
>   'Instantiate the XMLDOM Object that will hold the XML file.
>   set objXML = Server.CreateObject("Microsoft.XMLDOM")
> 
>   'Turn off asyncronous file loading.
>   objXML.async = false
> 
>   'Load the XML file.
>   objXML.load(strXMLFile)
> 
>   if len(strXSLFile) then
> 
>   'Instantiate the XMLDOM Object that will hold the XSL file.
> set objXSL = Server.CreateObject("Microsoft.XMLDOM")
> 
> 'Turn off asyncronous file loading.
> objXSL.async = false
> 
> 'Load the XSL file.
> objXSL.load(strXSLFile)
> 
> Response.Write(objXML.transformNode(objXSL))
> 
>   else
> 
> Response.Write (objXML.transformNode(objXML))
> 
>   end if
> 
> 
> if Err.Number then
> ErrorReportingRoutine()
> end if
> End Function
> 
> 
> '
> ' THANKS very much!!
> '
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords