2013-08-17 61 views
0

我在XSLT样式表中使用下面的JavaScript代码。它的工作没有for循环。但是,我收到了“<”附近的错误非法语法错误。请帮助我做到这一点。JavaScript for循环不工作在xslt

function activate(id) 
     { 
     try 
     { 
     alert('enter'); 
     var table = document.getElementById('billmain'); 
     var valueImp=""; 
     alert(table.rows.length) 

     for(i=1; i <table.rows.length; i++) 
     { 
     valueImp = table.rows[i].cells[0].innerHTML; 
     alert(valueImp); 
     } 
     return false; 
     }catch(ex) 
     { 
     alert(ex.Message); 

     } 
     } 
+2

jsfiddle please? –

+0

或至少张贴标记 –

回答

2

好XSLT样式表是一个XML文档,XML语法规则适用这意味着你需要躲避<小于号为&lt;或例如使用CDATA节

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 

<xsl:output method="html"/> 

<xsl:template match="/"> 
    <html> 
    <head> 
     <title>Example</title> 
     <script><![CDATA[ 
function activate(id) 
     { 
     try 
     { 
     alert('enter'); 
     var table = document.getElementById('billmain'); 
     var valueImp=""; 
     alert(table.rows.length) 

     for(i=1; i <table.rows.length; i++) 
     { 
     valueImp = table.rows[i].cells[0].innerHTML; 
     alert(valueImp); 
     } 
     return false; 
     }catch(ex) 
     { 
     alert(ex.Message); 

     } 
     } 
]]></script> 
    </head> 
    <body> 
    <xsl:apply-templates/> 
    </body> 
</html> 
</xsl:template> 

<!-- further templates go here --> 
</xsl:stylesheet>