3

Hi I have one XSL variable

<xsl:variable name="QTime" select="response/lst/int[@name='QTime']"/> 

Now I need to pass this to JavaScript function. Please help me how to do this...

<span onmouseout='c();' onmouseover='s($numFound);'>

For example

<span onmouseout='c();' onmouseover='s(900);'>
Lukasz
  • 7,572
  • 4
  • 41
  • 50
Varun
  • 426
  • 3
  • 7
  • 18
  • You will need to explain in much more detail as to what you want achieve; do you want to use Javascript inside XSLT as an extension function, if so which XSLT 2.0 processor do you use? I think AltovaXML supports that (in the commercial edition http://manual.altova.com/AltovaXML/altovaxmlreporting/index.html?xextmsxsl.htm), Saxon not. And it is questionable whether you need that with XSLT 2.0 having `xsl:function` to write functions in XSLT. Or do you want to use Javascript in the HTML result document of your XSLT transformation? Do you use XSLT 2.0 on the server or on the client (SaxonCE)? – Martin Honnen Feb 27 '12 at 10:46
  • @Varun, accept the answer .. if it really helped you .. or else one would think, these answers didn't work and try to think of a new solution which is waste of time .. :| – Rookie Programmer Aravind Feb 27 '12 at 12:28

2 Answers2

3

Simple:

<span onmouseout='c();' onmouseover='s({$numFound});'>

The { and } are key here - when used in attributes, they are used by xslt as a short-hand to evaluate the contents under xslt rules. This is equivalent to:

<span onmouseout='c();'>
    <xsl:attribute name="onmouseover">s(<xsl:value-of select="$numFound"/>);</xsl:attribute>
</span>
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
2

I'm guessing you're generating some HTML with your XSL transformation. Then, you can try this:

<xsl:element name="span">
    <xsl:attribute name="onmouseout">
        <xsl:text>c();</xsl:text>
    </xsl:attribute>
    <xsl:attribute name="onmouseover" select="concat('s(', $numFound, ');')" />
</xsl:element>
Lukasz
  • 7,572
  • 4
  • 41
  • 50