2016-08-19 37 views
-1
'</xsl:stylesheet>  
function generatetable() { 
    var tbl="<table border='1' cellpadding='5px'><tr><th>customerId</th><th>name</th><th>country</th></tr>"; 
    for (var index = 0; index < customers.length; index++) { 
     console.log(customers[index].customerId); 
     var color = (index % 2 ==0) ? 'red': 'blue'; 
     tbl+="<tr style='background-color:"+color+"'><td>"+customers[index].customerId+"</td><td>"+customers[index].name+"</td><td>"+customers[index].country+"</td></tr>"; 
    } 
    tbl+="</table>"; 


     var dvTable = document.getElementById("dvTable").innerHTML=tbl; 
    } 
    <xsl:element name="DIV"> 
    <xsl:attribute name="ID ">dvTable</xsl:attribute> 
    </xsl:element> 
</xsl:stylesheet>' 

以上是来自xsl FILe之一的流程服务器端的代码片段,但它给了我customers.length;我也可以在xsl中添加上面的javascript代码。如何写jaavcsript里面xslt

+0

http://stackoverflow.com/questions/7444317/how-to-include-javascript-file-in-xslt如果你的错误是在customers.length,这是因为这个脚本没有客户数组来记录长度。 – Shilly

+0

对不起,我忘了在问题中添加这些行我有var customer = new Array(); –

回答

0

你想达到什么目的?

您是否想在转换过程中执行Javascript代码,并从XSLT中调用它?某些产品具有允许使用的扩展名(例如<msxsl:script>),但它们不属于标准语言的一部分。

是否要将Javascript复制到您正在生成的HTML页面中?在这种情况下,它只是普通文本,你可以像任何其他文本一样包含它。当然,和任何XML文档一样,尖括号和&符号必须正确转义。