Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 19th, 2004, 05:53 AM
Registered User
 
Join Date: Mar 2004
Location: Cambridge, , United Kingdom.
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
Reply With Quote
  #2 (permalink)  
Old March 19th, 2004, 06:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old March 19th, 2004, 06:23 AM
Registered User
 
Join Date: Mar 2004
Location: Cambridge, , United Kingdom.
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>

Reply With Quote
  #4 (permalink)  
Old March 19th, 2004, 06:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old March 19th, 2004, 06:45 AM
Registered User
 
Join Date: Mar 2004
Location: Cambridge, , United Kingdom.
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.

Reply With Quote
  #6 (permalink)  
Old January 25th, 2005, 04:20 PM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. Ive been looking for this.:)

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.