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

Re: Set the param value from JavaScript

Subject: Re: Set the param value from JavaScript
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 8 Nov 2000 10:22:42 +0000
javascript get param
Bharat,

> I am trying to set a param value using JavaScript but I am unable to access
> the right node, I am not sure about my xpath expression. I am using MSXML3
> in IE 5.5 browser
[snip]
> I am trying to set the startRow value using a JavaScript method and the
> following XPath string
>
> /***
> var s = document.XSLDocument.selectSingleNode("*/xsl:template[@match
> ='/']//xsl:apply-templates/xsl:with-param[@name='startRow']");
> alert(s.value);
> /****
>
> I am getting some object back from the selectSingleNode() method, but
> unable to set it's value. Am I doing it right?

The XPath looks probably correct - you might want to add a '/' at the
start to ensure that it's relative to the root node.

Looking at the MSXML documentation, I think that the problem is that
elements don't have a .value property.  .value applies to attribute
nodes, but not element nodes.  I think that you want .nodeValue
instead.

An alternative is to change the way that you're specifying the value
of the variable: use the @select attribute instead of the content of
the xsl:variable element:

  <xsl:variable name="startRow" select="1" />

You can then set it by setting the .value of the @select attribute
that you can get through:

  var s =
  document.XSLDocument.selectSingleNode("/*/xsl:template[@match =
  '/']//xsl:apply-templates/xsl:with-param[@name =
  'startRow']/@select");
  s.value = '3';

This is a better method because declaring a variable value through its
content actually creates a result tree fragment containing a text node
that has the value: it takes less space to hold the value of an
attribute than a node.
  
Finally, the purer XSLT way of affecting how a stylesheet processes
XML on a particular run would be to pass in parameters to the
stylesheet and use those to set the values of the parameters:

<xsl:param name="start" select="1" />
<xsl:param name="end" select="2" />

<xsl:template match="/">
   <xsl:apply-templates select="Status/Data">
      <xsl:with-param name="startRow" select="$start" />
      <xsl:with-param name="endRow" select="$end" />
   </xsl:apply-templates>
</xsl:template>

[Actually, as these would be global parameters, there's no need to
pass them into templates individually.]

The parameters can be passed into the stylesheet from a script using
something like:

  XSLStylesheet = new ActiveXObject('Msxml2.XSLTemplate');
  XSLStylesheet.stylesheet = document.XSLDocument;
  XSLTProcessor = XSLStylesheet.createProcessor();

  XSLTProcessor.input = XMLDOM;
  XSLTProcessor.addParameter('start', '3');
  XSLTProcessor.addParameter('end', '5');
  XSLTProcessor.transform();
  result = XSLTProcessor.output;

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.