我的xsl模板非常复杂,里面有很多需要js的。本来(.htm时)都挺好的,
我加入了xsl语言,改成xsl文件后,当用它格式化一个xml文件时,出错。
就连if(a>b){alert("liu")}
都出错。说什么:缺少')'真的不知道该如何解决高手指点。

解决方案 »

  1.   

    把javascript脚本放在xsl:comment和cdata里面,像下面那样
    <SCRIPT LANGUAGE="javascript">
                        <xsl:comment><![CDATA[function GetIEVersion()
    {
    try
    {
    if(!window.clientInformation)return false;
    if(window.clientInformation.appName.toLowerCase()!="microsoft internet explorer")return false;
    if(window.clientInformation.appVersion.toLowerCase().indexOf("msie")==-1)return false;
    var a=window.clientInformation.appVersion.toLowerCase().split(";");
    for(var i=0;i<a.length;i++)
    {
    a[i]=a[i].replace(" ","");
    if(a[i].indexOf("msie")==0)
    {
    var version=a[i].substr(4,a[i].indexOf(".")-2);
    return version;
    }
    }
    }
    catch(exception)
    {
    }
    return false;
    }window.IEVersion=GetIEVersion();if(parseInt(window.IEVersion)<6)document.write("<style>textarea.content { behavior:url('/Expert/xsl/tacontent.htc')}</style>");
    function mailto1()
    {
    document.mailto.email.value='';
    var tmpText=prompt('请输入您朋友的EMail:',document.mailto.email.value);
    if(tmpText){
    document.mailto.email.value = tmpText;
    document.mailto.submit();
    }
    }]]>//</xsl:comment>
                    </SCRIPT>
      

  2.   

    你可以
    <script>
    <![CDATA[
    if(a>b){alert("liu")}
    ]>
    </script>不过你要分清楚你的js文件在服务器端执行还是在客户端
      

  3.   

    下面的脚本,方里面就出错。就是有> 和 <的地方都出错
    <script language="javascript">
    var picN=-1
    function first(){
    picN=0
    showPict();
    }
    function back(){
    picN--
    if(picN<0) picN=0;
    document.albumlist.albumtitle.selectedIndex=picN+2;
    showPict();
    }
    function forw(){
    picN++
    if(picN>0) picN=0
    document.albumlist.albumtitle.selectedIndex=picN+2;
    showPict();
    }
    function last(){
    picN=sum_photo
    showPict();
    }
    function showPict(){
    switch (picN) {
    case 0: CardCode="1099276339.jpg"; break;  }
    document.cardpict.src="http://loveimg.163.com/myphotoes/78/50/yangming_8888/"+CardCode;
    }
    function showALBUM() {
    if (document.albumlist.albumtitle.selectedIndex>=2){
    picN = document.albumlist.albumtitle.selectedIndex-2;
    showPict();
    }
    }
    function openPict()
    {
    if (picN==-1) { document.albumlist.albumtitle.selectedIndex=2;showALBUM();}
    switch (picN) {
    case 0: CardCode="1099276339.jpg"; break; 
     
    }
    srcIMG="http://loveimg.163.com/myphotoes/78/50/yangming_8888/"+CardCode;
    var newWin=window.open(srcIMG,"myalbum","status=no,scrollbars=1,resizable=1,width=800,height=600");
    }</script>
      

  4.   

    我实在数据库中读出数据,然后用StringBuilder生成一个xml串,(一个元素一个元素的构造的),在xml串中引用了这个xsl用于格式化。最后用Response.Write(stringbuilder.ToString());这种情况 xsl中的js在那里执行。
      

  5.   

    用了46539492(#我思故我在#) 的方法,还出错,不过错误不同了:
    这次提示的错误是:语法错误<script language="javascript">
    <xsl:comment>
    <![CDATA[
    var picN=-1
    function first(){
    picN=0
    showPict();
    }
    function back(){
    picN--
    if(picN<  0) picN=0;
    document.albumlist.albumtitle.selectedIndex=picN+2;
    showPict();
    }
    function forw(){
    picN++
    if(picN  > 0) picN=0
    document.albumlist.albumtitle.selectedIndex=picN+2;
    showPict();
    }
    function last(){
    picN=sum_photo
    showPict();
    }
    function showPict(){
    switch (picN) {
    case 0: CardCode="1099276339.jpg"; break;  }
    document.cardpict.src="http://loveimg.163.com/myphotoes/78/50/yangming_8888/"+CardCode;
    }
    function showALBUM() {
    if (document.albumlist.albumtitle.selectedIndex>=2){
    picN = document.albumlist.albumtitle.selectedIndex-2;
    showPict();
    }
    }
    function openPict()
    {
    if (picN==-1) { document.albumlist.albumtitle.selectedIndex=2;showALBUM();}
    switch (picN) {
    case 0: CardCode="1099276339.jpg"; break; 
     
    }
    srcIMG="http://loveimg.163.com/myphotoes/78/50/yangming_8888/"+CardCode;
    var newWin=window.open(srcIMG,"myalbum","status=no,scrollbars=1,resizable=1,width=800,height=600");
    }
    ]]>//</xsl:comment>
    </script>  
      

  6.   

    <script language="javascript">
    <![CDATA[]>
    </script>
    即可