[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Passing javascript value into xsl

Subject: Re: Passing javascript value into xsl
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 6 Feb 2001 13:32:09 +0000
javascript value
Hi Mick,

> I want to use this value as a filter for another bit of xsl:
>
> <xsl:for-each select="mabinogion/tale[talename=' ->x goes here<- ']">
>         <xsl:for-each select="manuscript">
>                 <xsl:value-of select="manuscriptname"/>
>                 <br/>
>         </xsl:for-each>
> </xsl:for-each>

OK. The x is declared in the Javascript within your page, and you want
it to be used within a stylesheet that you're using from that
Javascript. The standard way of making that happen is to pass the
value of x in as a parameter to the stylesheet. You need to declare
the parameter at the top level of the stylesheet:

<xsl:param name="x" select="'default'" />

and then use it in the select expression as above:

  <xsl:for-each select="mabinogion/tale[talename = $x]">
     ...
  </xsl:for-each>

How you pass in the value depends on the XSLT processor.  I guess that
you're using MSXML3, so you want something along the lines of:

   var x = tales.tales.value;
   ...
   XSLTProcessor.addParameter('x', x);
   XSLTProcessor.transform();
   list.innerHTML = XSLTProcess.output;

Note that the stylesheet here is run on an entire source XML, and
everything that it produces is put within the innerHTML of the list,
so you want it to only produce whatever you want within the list.

Another way of doing it if you only want a bit of what the stylesheet
produces is to use the MSXML transformNode() method.  To use that with
a parameter, you need to change the XSLT DOM by hand, something like:

  var xParam = stylesheet.selectSingleNode("/*/xsl:param[@name = \'x\']/@select");
  xParam.value = x;
  list.innerHTML = sourceNode.transformNode(stylesheet);

There are examples in the MSXML SDK documentation and on the Microsoft
site.

I hope that helps,

Jeni

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



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.