|
| =?Utf-8?Q?Call_a_function_defined_in_=E2=80=9Cmsxs?= |
 |
Thu, 3 Apr 2008 07:11:01 -0700 |
(Beginner's question)
Xml file contents:
<Results>
<Iteration Sample="1" Pressure="14"
Derivative="0" Regression="0" />
<Iteration Sample="2" Pressure="16"
Derivative="0" Regression="0" />
<Iteration Sample="3" Pressure="10"
Derivative="0" Regression="0" />
<Iteration Sample="4" Pressure="25"
Derivative="0" Regression="0" />
</Results>
With XSLT file:
...
<xsl:template match="Iteration">
<td onclick="user:onClickHandler( )">
<xsl:value-of select="@Sample" />
</td>
<td>
<xsl:value-of select=" @Dervative" />
</td>
<td onclick="clickIt()">
<xsl:value-of select="@Regression" />
</td>
</xsl:template>
...
<msxsl:script language="JScript"
implements-prefix="user">
function onClickHandler( )
{
}
</msxsl:script>
Please explain how I can call “onClickHandler” when user clicks somewhere
inside “Sample” cell and pass sample number to this function (current
implementation throws axception “Object required”)
Thank you,
Eugene
|
| Post Reply
|
| =?Utf-8?Q?Re:_Call_a_function_defined_in_=E2=80=9C?= |
 |
Thu, 3 Apr 2008 08:20:01 -0700 |
Thank you.
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>
"Martin Honnen" wrote:
> Eugene wrote:
>
> > <xsl:template match="Iteration">
> > <td onclick="user:onClickHandler( )">
>
> That looks as if you want to use script in the HTML result document of
> the transformation. In that case forget about msxsl:script, simply do e.g.
> <td onclick="onClickHandler();">
> ...
> </td>
> <script type="text/javascript">
> function onClickHandler () {
> ...
> }
> </script>
> that is simply insert a HTML script element in the transformation result.
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
|
| Post Reply
|
| Re: =?utf-8?Q?Call_a_function_defin?= |
 |
Thu, 03 Apr 2008 16:37:12 +020 |
* Eugene wrote in microsoft.public.xsl:
><msxsl:script language="JScript"
implements-prefix="user">
> function onClickHandler( )
> {
> }
></msxsl:script>
>
>Please explain how I can call “onClickHandler” when user clicks
somewhere
>inside “Sample” cell and pass sample number to this function (current
>implementation throws axception “Object required”)
Instead of <msxsl:script> use a normal <script> element; the former
is
only if you want to execute functions while the document is being trans-
formed.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
|
| Post Reply
|
| Re: Call a function defined in =?UTF-8?B?4oCcbXN4c2w6c2NyaXB04oCd?= |
 |
Thu, 03 Apr 2008 16:49:43 +020 |
Eugene wrote:
> <xsl:template match="Iteration">
> <td onclick="user:onClickHandler( )">
That looks as if you want to use script in the HTML result document of
the transformation. In that case forget about msxsl:script, simply do e.g.
<td onclick="onClickHandler();">
...
</td>
<script type="text/javascript">
function onClickHandler () {
...
}
</script>
that is simply insert a HTML script element in the transformation result.
--
Martin Honnen --- MVP XML
|
| Post Reply
|
| Re: Call a function defined in =?UTF-8?B?4oCcbXN4c2w6c2NyaXB04oCd?= |
 |
Thu, 03 Apr 2008 17:54:22 +020 |
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
|
| Post Reply
|
|
|
|
|
|
|
|
|
|