To embed JavaScript for the aid of transformation you can use <xsl:script>, but it is limited to Microsoft's XML objects implementation. Here's an example:
scripted.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="scripted.xsl"?>
<data a="v">
ding dong
</data>
scripted.xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:script implements-prefix="local" language="JScript"><![CDATA[
function Title()
{
return "Scripted";
}
function Body(text)
{
return "/" + text + "/";
}
]]></xsl:script>
<head>
<title><xsl:eval>Title()</xsl:eval></title>
</head>
<body>
<xsl:for-each select="/data"><xsl:eval>Body(nodeTypedValue)</xsl:eval></xsl:for-each>
</body>
</html>
The result in Internet Explorer (or if you just use MSXML from COM/.NET) is:
<html>
<head>
<title>Scripted</titlte>
</head>
<body>
/ding dong/
</body>
</html>
It doesn't appear to support the usual XSL template constructs and adding the root node causes MSXML to go into some sort of standards mode where it won't work.
I'm not sure if there's any equivalent functionality in standard XSL, but I can dream.