Here is an existing example of using XSLT and Javascript together.
This transformation produces an html page with javascript in which pressing on a number-button produces the square of that number:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- squareAsHTMLJS1.xml: create an HTML document with JavaScript that
interactively computes the square of each "number" element read from
the source tree. -->
<xsl:template match="/"> <!-- Set up web page -->
<html>
<head>
<title>Squares</title>
<script language="JavaScript1.2">
function showSquare(n) {
alert("the square is " + n*n);
}
</script>
<style> <!-- Put a little CSS in -->
body { font-family: arial,helvetica; }
h1 { font-size: 14pt }
p { font-size: 10pt}
</style>
</head>
<body>
<h1>Squares</h1>
<p>Click a button to see the square of that number.</p>
<form>
<xsl:apply-templates/>
</form>
</body>
</html>
</xsl:template>
<xsl:template match="number">
<p><input type="button" value=" {.} " onClick="showSquare({.})"/></p>
</xsl:template>
</xsl:stylesheet>
when this transformation is applied on this XML document:
<numbers>
<number>2</number>
<number>11</number>
<number>100</number>
<number>-5</number>
</numbers>
the result is:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Squares</title><script language="JavaScript1.2">
function showSquare(n) {
alert("the square is " + n*n);
}
</script><style>
body { font-family: arial,helvetica; }
h1 { font-size: 14pt }
p { font-size: 10pt}
</style></head>
<body>
<h1>Squares</h1>
<p>Click a button to see the square of that number.</p>
<form>
<p><input type="button" value=" 2 " onClick="showSquare(2)"></p>
<p><input type="button" value=" 11 " onClick="showSquare(11)"></p>
<p><input type="button" value=" 100 " onClick="showSquare(100)"></p>
<p><input type="button" value=" -5 " onClick="showSquare(-5)"></p>
</form>
</body>
</html>
You can play with this here: http://www.snee.com/xml/trxml33/numbersJS1.xml
And see more explanations by the author here: http://www.xml.com/pub/a/2003/02/05/tr.html