This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Set the param value from JavaScript
- To: Bharat dot Chintapally at CommerceQuest dot com
- Subject: Re: Set the param value from JavaScript
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Wed, 8 Nov 2000 10:22:42 +0000
- CC: XSL-List at mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <OF70A8EEC6.320391CF-ON85256990.006DBE12@commercequest.com>
- Reply-To: xsl-list at mulberrytech dot com
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