xsl-list
[Top] [All Lists]

Re: Parameters set by user

2002-08-29 15:49:38
Hi Matthias,

I was trying to find information on how to pass a parameter from the
HTML page down to the XSL, do invoke portions of the stylesheet.
From what results to me, this depends on the transforming machine
used. I found information on how to pass parameter values to XALAN
via the command line. How would this be done instead from an HTML
page when using Cocoon?

Cocoon can be set up to pass either particular parameters or all
request parameters into the stylesheet. To do either, you need to set
up the sitemap so that parameters are passed into the particular
transformation.

For example, you could have something like:

  <map:match pattern="search/*">
    <map:generate src="list.xml" />
    <map:transform src="list.xsl">
      <map:parameter name="search" value="{1}" />
    </map:transform>
    <map:serialize />
  </map:match>

which would, whenever you had a URL of the form:

  .../search/keyword

transform list.xml with list.xsl, passing in the keyword as the value
of the $search parameter. So if you had the URL:

  .../search/a

then the $search parameter would be set to the string "a" and so on.

Alternatively, you could have:

  <map:match pattern="search">
    <map:generate src="list.xml" />
    <map:transform src="list.xsl">
      <map:parameter name="use-request-parameters" value="true" />
    </map:transform>
    <map:serialize />
  </map:match>

which means that when the URL has request parameters, for example:

  .../search?search=a

then the request parameters are passed in as parameters to the
stylesheet as well. So the above URL would pass in the value "a" as
the value of the parameter $search.

If you're getting the user to type in a search term in an input box,
then the latter is probably what you're after. If you want to
parameterise your XSLT and have links that lead to different
transformations (e.g. for a paging application) then you can use
either technique, and the former is slightly better (I think) because
you have a distinct URL for each "resource" that you're accessing
[very RESTful].

BTW, you still need to set up your stylesheet in the same way as you
would if you were passing in parameters from the command line -- the
stylesheet needs to have a top-level parameter declaration, e.g.:

<xsl:param name="search" select="'defaultSearchTerm'" />

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>