在xsl中是可以使用JavaScript等脚本语言的,但要遵守XML规范。 所以要用 <xsl:comment> <![CDATA[ ]]> </xsl:comment>括起来。
例如以下一个xsl可以实现滚屏效果:
<?xml version="1.0" encoding="utf-8"?>
<html xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<head>
<script language="JavaScript" >
<xsl:comment>
<![CDATA[
var position = 0;
var bswitch = 0;
function scroller() {
// document.getElementById("aa").innerHTML =document.body.clientHeight;
if (bswitch==0 && position <=document.body.scrollHeight-document.body.clientHeight) {
position++;
}else{
bswitch = 1;
}
if (bswitch==1 && position >=0) {
position--;
}else{
bswitch = 0;
}
scroll(0,position);
clearTimeout(timer);
var timer = setTimeout("scroller()",30);
timer;
}
]]>
</xsl:comment>
</script>
</head>
<body bgcolor="#333355" style="color:#33FF66;overflow-x:hidden;overflow-y:hidden">
<xsl:for-each select="rss/channel/item">
<h1>
<xsl:value-of select="title"/>
</h1>
<h3>
<xsl:value-of select="description"/>
</h3>
</xsl:for-each>
<script language="JavaScript">
<xsl:comment>
<![CDATA[
scroller() ;
document.body.innerHTML = document.body.innerHTML.replace(/>/g,">").replace(/</g,"<");
//document.body.innerHTML = document.body.innerHTML.replace("<", "<");
//document.body.innerHTML = document.body.innerHTML.replace("&rt;", ">");
]]>
</xsl:comment>
</script>
</body>
</html>