RE: [xsl] Passing parameters to xsl-stylesheet

Subject: RE: [xsl] Passing parameters to xsl-stylesheet
From: "Andrew Welch" <andrew@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 31 Jan 2002 14:55:52 -0000
Hi,

The following ASP will get two params from the request and pass them into
your stylesheet.  For example, if you save this as addParams.asp then you
can supply params by calling it using:

<a href="addParams.asp?param1='hello'&param2='world'">...</a>

Then in your stylesheet you need to add some lines to receive the params,
like this:

<xsl:stylesheet xmlns:xsl.......
<xsl:param name="param1"/>
<xsl:param name="param2"/>

Then you can access the params in your stylesheet using $param1 and $param2.

So, <xsl:value-of select="$param1"/> would produce 'hello'.

You can change the names as long as you change them throughout, and have as
many as you like (although I guess there is some kind of limit...anyone?)

This should give you a start

cheers

andrew

(ps. this code is in VB... if anyone has the javascript equivalent that
would be cool)

=====the asp========

<% 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("/yourxml.xml"))

   Set xsl = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
   xsl.async = false
   xsl.load (Server.MapPath("/yourxsl.xsl"))

   Set template = Server.CreateObject("MSXML2.XSLTemplate")
   template.stylesheet = xsl
   set processor = template.createProcessor()

   processor.input = xml

   firstParam = Request.querystring("param1")

   if firstParam <> "" then
     processor.addParameter "param1", searchType
   end if


   secondParam = Request.querystring("param2")

   if secondParam <> "" then
     processor.addParameter "param2", searchVal
   end if

   processor.transform()

   Response.write (processor.output)

   Set xml = Nothing
   Set xsl = Nothing
%>

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Ragulf
Pickaxe
Sent: Thursday, January 31, 2002 2:04 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Passing parameters to xsl-stylesheet


Hello all,

What is the exact syntax of passing an argument (parameter) from an asp-page
to an xsl-stylesheet and what is the syntax for recieving the parameter in
the stylesheet?

I have a stylesheet that sorts an xml-file by various methods and want the
user to be able to choose which method to sort by.

Sorry, I know this is a real newbee question, and I have seen answers for it
before, but I can't find the answer in the archive and Michael Kay only
describe the passing in general terms that I can find (p. 284 in second
edition).

Sincerly
Raguld Pickaxe :)

_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail.
http://www.hotmail.com


 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