[xsl] Onmouseover and onmouseout in xsl

Subject: [xsl] Onmouseover and onmouseout in xsl
From: "Emsley, I (Iain)" <I.Emsley@xxxxxxxx>
Date: Mon, 14 Apr 2008 09:49:17 +0100
Morning,

I am currently trying to embed an onmouseover event in my first XSL
sheet but am having difficulties in getting the event to work.

Have I set the JavaScript up correctly in XSL? Also, is there a best
practice on embedding JS in XSLT - for instance is it best to link to an
external file (the same with CSS) and if so, what is the best way of
doing this?

Many thanks in advance for any help,

Iain

The code that I have so far is:
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">

<html>
<head>
<style><xsl:comment>
h2 {
text-align: center;
font-family: Verdana;
}
td {
  font-family: Arial;
  text-align: left;
}

</xsl:comment>
</style>
<script type="text/javascript">
<![CDATA[

var newWindow;

function newWindow {
	if(!newWindow || newWindow.closed) {
	newWindow = window.open("test.html","sub", "status,height=200,
width=300");
	//delay writing whilst Windows catches up
	setTimeout("writetoWindow()", 50);
} else if (newWindow.focus) {
	//new Window is already open so bring to front
	newWindow.focus();
	}
}//end newWindow
function writetoWindow() {
	var newContent = "<html><body><p>Hello World!</p></body</html>";
	newWindow.document.write(newContent);
	newWindow.document.close();
}
function close() {
	newWindow.close();

}

]]>
</script>
<title>Charles Dickens</title>
</head>
<body>
<table name="Charles Dickens">
<tr>
<td colspan="3">
<h2>Charles Dickens</h2>
</td>
</tr>
<xsl:for-each select="dickens/text">
<tr>
<td>
<xsl:attribute name="onmouseover">newWindow()</xsl:attribute>
<xsl:attribute name="onmouseout">close()</xsl:attribute>
Diffs
</td>
<td><strong><xsl:value-of select="lineno"/></strong></td>
<td><xsl:value-of select="line"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Current Thread