Re: [xsl] using parameter in xsl created within html wrapper

Subject: Re: [xsl] using parameter in xsl created within html wrapper
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 9 Apr 2002 14:56:04 +0100
Hi,

> is it possible to pass a string variable (created in javascript
> within html wrapper) to be used by xsl in an xsl:if
> test=($parameterString)? If yes, does anyone have any code examples.
> I am trying to create a 'filter' which users can select (clicking
> on/off check boxes) to turn on/off display of desired groups of xml
> data. All filtering to be client-side processing.

Yes, you can do this, as long as you don't expect $parameterString to
be an XPath expression itself.

For example, you can declare the parameter:

<xsl:param name="parameterString" select="'groupA'" />

and then do something like:

  <xsl:if test="contains($parameterString, 'groupA')">
    ... process groupA elements ...
  </xsl:if>

Passing in parameters to stylesheets involves scripting the
transformation on the client, and using the MSXML3 or MSXML4 methods
to do so, via XSLTemplate and XSLProcessor objects. The MSXML
documentation contains examples -- look up the addParameter() method
for an example.

> Any other alternatives for client-side filtering of xml data where
> multiple selections can be made (i.e., I want groupA, groupB and
> groupD data displayed, but not groupC) or - I just want groupB data
> - could be any combination of groupA thru groupX.

You could consider doing this through client-side scripting of the
display of the groups through their CSS style rather than through
XSLT. For example, define a function in the HTML that you generate
that toggles between showing or hiding the passed element:

  function toggle(element) {
    if (element.style.display = 'block') {
      element.style.display = 'none';
    } else {
      element.style.display = 'block';
    }
  }

and then have buttons that you click to show or hide the element:

  <a onclick="toggle(groupA)">Show/Hide</a>
  <div id="groupA">
    ...
  </div>

Doing it like this is likely to be less effort for the browser, I
think, and it makes the transformation a lot easier :)
  
Cheers,

Jeni

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


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


Current Thread