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

2
  • stackoverflow.com/questions/7444317/… If your error is on customers.length, it's because this script has no customers array to log the length of. Commented Aug 19, 2016 at 13:28
  • Sorry I forget to add those line in the question I have var customer =new Array() ; Commented Aug 19, 2016 at 13:42

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.