Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - =?Utf-8?Q?Re:_Call_a_function_defined_in_=E2=80=9C?= =?Utf-8?Q?msxsl:script=E2=80=9D_block_from_=E2=80=9Conclic?= =?Utf-8?Q?k=E2=80=9D?= [Thread Next] Re: Call a function defined in =?UTF-8?B?4oCcbXN4c2w6c2NyaXB04oCd?= =?UTF-8?B?IGJsb2NrIGZyb20g4oCcb25jbGlja+KAnQ==?=To: NULL Date: 4/3/2008 5:54:00 PM
Eugene wrote:
> How can I pass a variable or a parameter to this function?
>
> i. e.:
>
> <xsl:param name="sampleParam" select="@Sample" />
> ...
> <td onclick="onClickHandler( $sampleParam );">
> ...
> </td>
> <script type="text/javascript">
>
> function onClickHandler (sampleParam ) {
> ...
> }
> </script>
You have to be aware that your XSLT stylesheet constructs a HTML
document where in that case the HTML document has some script embedded.
You can't pass parameters in the XSLT stylesheet to the script functions
as the XSLT transformation is executed first and has as its result the
HTML document with the script and the script is executed later. What you
can do however is construct JavaScript code where you use values of XSLT
parameters or values.
So you can use attribute value templates for instance to do e.g.
<td onclick="onClickHandler({$sampleParam});">
but you need to make sure that you construct syntactically correct
JavaScript code. Thus the above will work for instance if $sampleParam
has a number value (e.g. 2.5) as that results in the JavaScript code
onClickHandler(2.5);
If the $sampleParam is a string however then you need to make sure you
construct a JavaScript string literal e.g.
<td onclick="onClickHandler('{$sampleParam}');">
That will work as long as $sampleParam does not contain a single quote.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
