tags:

views:

760

answers:

4

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"&gt;
        <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 ........

+2  A: 

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.

Bhushan
A: 

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.

jsight
A: 

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');"

Rashmi Pandit
Hi Rashmi,I am using XSL Script and calling Javascript function defined in other file. Can you please eleborate more on above solution as I have tried this and colour is not changing on mouseover event in firefox (Linux)
OK ... so your javascript is in a separate js file. In that case do the foll:1. Make sure that your page on which you are calling this xslt includes the javascript file. For this you should have the following in the html head:<script language="javascript" src="abc.js" type="text/javascript"></script>2. In your xslt, simply say:onMouseover="javascript:changeColor(event, 'red');"This should work. If it doesn't, then in your changeColor function, put an alert statement in the beginning e.g. alert('Entered changecolor function');and see if atleast the alert gets displayed.
Rashmi Pandit
A: 

Hi Rashmi,

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

Have you specified the correct src path in your script tag? Are you using onMouseover="javascript:changeColor(event, 'red');" ?
Rashmi Pandit