Oong
Oong

Reputation:

XSL + Java Script Issue ... Unable to call javascript function from xsl file

I am a newbie to XSL world and facing few issues with XSL

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:template match="/">
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <link rel="stylesheet" type="text/css" href="mycss.css" />
        <script language="javascript"  type="text/javascript" >
                      <xsl:text></xsl:text>
        </script>

        </head>
    <body>

    <table>
        <tr bgcolor='yellow' onMouseover="changeColor(event, 'red');"> MYTEXT 
        </tr>
    </table>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

and MY XML file is

<COUNTRY>
        <CITY>X</CITY>
        <CITY>Y</CITY>
</COUNTRY> 

and my Javascript file is

   function changeColor(e,highlightcolor){
      source=ie? event.srcElement : e.target
      source.style.backgroundColor=highlightcolor
   }

Issue is not mouse over , Color doesn't changes in browser ........

Upvotes: 1

Views: 2549

Answers (4)

Mita
Mita

Reputation:

There is no alert thrown in firefox .... I doubt whether function is being called or not.

Upvotes: 0

Rashmi Pandit
Rashmi Pandit

Reputation: 23848

If even your alerts are not getting displayed (jsight's suggestion above) then do this: If your javascript is not in xslt but in the html instead, call the function as follows:

onMouseover="javascript:changeColor(event, 'red');"

If your script is in the xslt file:

  1. In xsl:stylesheet, specify

    xmlns:myscript='http://www.example.com/myscript'

  2. Declare the script section as

    function changeColor(e,highlightcolor){ source=ie? event.srcElement : e.target source.style.backgroundColor=highlightcolor}

  3. Call the function as:

    onMouseover="myscript:changeColor(event, 'red');"

Upvotes: 0

jsight
jsight

Reputation: 28419

I'd suggest sprinkling your changeColor function with alerts to check your conditions. Ie, before the first line of the function:

alert("IE?" + ie);

Then after your first line:

alert("Src: " + source);

Then before the line that changes the color:

alert("style: " + source.style);
alert("bgclr: " + source.style.backgroundColor);

Obviously, you could do similar things with a Javascript debugger, but I'm assuming that you aren't using one.

Upvotes: 0

Bhushan Bhangale
Bhushan Bhangale

Reputation: 10987

In your XSL I don't see any JavaScript file (.js) included nor I see the javascript function you mentioned. Secondly where is the ie variable defined which you using in the function changeColor?

Check the html which is getting generated by doing the view source on your browser to see if all is correct. Add some alerts in your function to confirm if it actually gets called.

Upvotes: 2

Related Questions