-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>'

Above is the code snippet from one of the xsl FILe which is process sever side but it gave me error on customers.length; also <, >symbols how can I add above javascript code in xsl.

Prem Kumar
  • 1
  • 1
  • 2
  • http://stackoverflow.com/questions/7444317/how-to-include-javascript-file-in-xslt If your error is on customers.length, it's because this script has no customers array to log the length of. – Shilly Aug 19 '16 at 13:28
  • Sorry I forget to add those line in the question I have var customer =new Array() ; – Prem Kumar Aug 19 '16 at 13:42

1 Answers1

0

What are you trying to achieve?

Do you want to execute the Javascript code during the transformation, invoking it from something in the XSLT? Some products have extensions that allow that (e.g. <msxsl:script>) but they are not part of the standard language.

Do you want to copy the Javascript into the HTML page you are generating? In that case it's just ordinary text, you can include it like any other text. Of course, as in any XML document, angle brackets and ampersands have to be properly escaped.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164