[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: ASP and MSXML AddParameter

Subject: Re: ASP and MSXML AddParameter
From: "Marcus Andersson" <marcan@xxxxxxx>
Date: Mon, 7 Jul 2003 23:55:45 +0200
server.createobject msxml
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:  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.