Wrox Programmer Forums
|
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 19th, 2004, 05:53 AM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rj_mayer
Default Passing parameters from ASP (VBScript) to XSLT

I need to pass a parameter to an XSL document from ASP (VBScript). I have come up with the following code, but the parameters are not displayed when passed to the XSL sheet. Can anyone help?

function showxmldata(strXMLFile, strXSLFile, strParam)

     dim blnXMLOK
     dim blnXSLOK
     dim strFilesErr

     set xmlDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocumen t")
     set xslDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocumen t")
     'xmlDoc.preserveWhiteSpace = true
     blnXMLOK = xmlDoc.load(strXMLFile)
     blnXSLOK = xslDoc.load(strXSLFile)

     if blnXMLOK and blnXSLOK then
          'check for parameters
          response.write "test - strParam = (" & strParam & ")" '***there is a value here
          if strParam <> "none" then
               set xslt = Server.CreateObject("MSXML2.XSLTemplate")
               set xslt.stylesheet = xslDoc
               Set xslProc = xslt.createProcessor()
               xslProc.input = xmlDoc
               xslProc.addParameter "Chapel", cstr(strParam)
               xslProc.transform
               sOutput = xslProc.output
               response.write sOutput
               set xslProc = nothing
               set xslt = nothing
          else
               Response.Write(xmlDoc.transformNode(xslDoc))
          end if
     else
          if not blnXMLOK then
                      strFilesErr = strFilesErr & "strXMLFile: " & strXMLFile
          end if
          if not blnXSLOK then
               strFilesErr = "<br>" & strFilesErr & "strXSLFile: " & strXSLFile
          end if
          DisplayError(strFilesErr)
     end if

     set xmlDoc = nothing
     set xslDoc = nothing
end function
 
Old March 19th, 2004, 06:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Your method of passing parameters is fine. Maybe there is some problem in your XSLT?

BTW this snippet:
  xslProc.transform
  sOutput = xslProc.output
  response.write sOutput

can be replaced by this:
  xslProc.output = Response
  xslProc.transform

It's more efficient to stream the transform result directly to the Response object - this also has the advantage of preserving encoding.

Anyway, that's nothing to do with your problem - let's see your XSLT and if poss a snippet of your XML.

rgds
Phil
 
Old March 19th, 2004, 06:23 AM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rj_mayer
Default

Thanks for this. It's a relief to know that there is nothing fundamentally wrong with the ASP!

My XML file can be found at http://www.techybits.net/ccsl/data/service.xml

My XSLT is as follows ...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:param name="Chapel"/>

 <html>
 <body>
 <h1>Service in Detail for SID:172 --- <xsl:value-of select="$Chapel"/></h1>

    <xsl:for-each select="CHAPELDATA/SERVICE">
    <xsl:sort select="field[@id='Date']"/>
<xsl:value-of select="$Chapel"/>
    <xsl:if test="field[@id='SERVICEID']='SID:172'">

        <table border="1" cellpadding="2">

            <xsl:for-each select="field">
                <tr><td><xsl:value-of select="@id"/></td>
                <td><xsl:value-of select="field_value"/></td></tr>
            </xsl:for-each>
        </table>

    </xsl:if>
    </xsl:for-each>

 </body>
 </html>
</xsl:template>
</xsl:stylesheet>

 
Old March 19th, 2004, 06:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Move the <xsl:param name="Chapel"/> outside of the <xsl:template match="/">...</xsl:template> block. You need it to be a top-level parameter if you want to externally supply a value.

rgds
Phil
 
Old March 19th, 2004, 06:45 AM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rj_mayer
Default

That's great. It works. Thanks so much Phil.

 
Old January 25th, 2005, 04:20 PM
Registered User
 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. Ive been looking for this.:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Access page parameters from vbscript jnralfe ASP.NET 1.0 and 1.1 Basics 1 September 17th, 2004 05:20 AM
Passing 10 parameters from ASP (VBSript) to COM pankaj_pp Classic ASP Basics 0 May 24th, 2004 05:13 AM
Passing parameters to an XSLT kiril XSLT 1 May 15th, 2004 10:29 PM
Passing parameters between 2 asp files spraveens Classic ASP Databases 3 September 23rd, 2003 02:49 PM
Passing Parameters between 2 asp files spraveens Classic ASP Basics 1 September 17th, 2003 10:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.