This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: passing parameter via asp
- From: "Andrew Welch" <awelch at piper-group dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 22 Feb 2002 09:09:54 -0000
- Subject: RE: [xsl] passing parameter via asp
- Reply-to: xsl-list at lists dot mulberrytech dot com
>Hi, i guess this is a question asked by millions of people already,
>however, i couldn't find the right one for my problem. how do a pass a
>parameter set by the end-user (via the form element in HTML) to a xsl
>stylesheet and return the transformed result to the user.
Hi,
Here is the code you are looking for. This ASP script currently takes two
parameters (to demonstrate how to have more than one), searchValue1 and
searchValue2. So, if you call the asp 'searchXML.asp' you could pass params
to it by using:
searchXML.asp?searchValue1='foo'&searchValue2='bar'
So within your html form, you would have:
<form name="yourForm" action="searchXML.asp">
<input type="text" id="searchValue1"/>
<input type="text" id="searchValue2"/>
<input type="submit"/>
</form>
The ASP code would look like this (using msxml3):
<% Response.Buffer=True %>
<% Dim xml
Dim xsl
Dim template
Dim processor
Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xml.async = false
xml.load (Server.MapPath("yourXMLFile.xml"))
Set xsl = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xsl.async = false
xsl.load (Server.MapPath("yourXSLFile.xsl"))
Set template = Server.CreateObject("MSXML2.XSLTemplate")
template.stylesheet = xsl
set processor = template.createProcessor()
processor.input = xml
searchValue1 = Request.querystring("searchValue1")
if searchValue1 <> "" then
processor.addParameter "param1", searchValue1
end if
searchValue2 = Request.querystring("searchValue2")
if searchValue2 <> "" then
processor.addParameter "param2", searchValue2
end if
processor.transform()
Response.write (processor.output)
%>
And finally, within your stylesheet you need accept the params with some
top-level elements:
<xsl:stylesheet...
<xsl:param name="searchValue1"/>
<xsl:param name="searchValue2"/>
You can then access them using $searchValue1 and $searchValue2
cheers
andrew
===
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.325 / Virus Database: 182 - Release Date: 2/19/02
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list