简体   繁体   中英

How do I get a less than in a javascript for loop in XSL to work?

I am using CDATA to escape the script but in IE8's debugger I still get this message: "Expected ')'" in the for loop conditions. I am assuming it still thinks that the ; in the < generated by CDATA is ending the loop conditions.

Original script in my XSL template:

<script type="text/javascript" language="javascript">  
<![CDATA[
    function submitform(form){
        var oErrorArray = new Array();
        for (i=0;i<form.length;i++) 
        eval("oErrorArray["+i+"]=oError"+i);
        var goForm = true;
        for(i=0;i<form.length;i++) {
            oErrorArray[i].innerHTML = "";
            if(form[i].value="")){
                oErrorArray[i].innerHTML = "Error - input field is blank";
                goForm = false;
            }           
        }
        if(goForm == true) form.submit();
    }
    function resetform(form){
        form.reset();
    }
]]>
</script>

Code generated after transformation (from IE8 debugger) :

<script type="text/javascript" language="javascript">
    function submitform(form){
        var oErrorArray = new Array();
        for (i=0;i&lt;form.length;i++) 
        eval("oErrorArray["+i+"]=oError"+i);
        goForm = true;
        for(i=0;i&lt;form.length;i++) {
            oErrorArray[i].innerHTML = "";
            if(form[i].value="")){
                oErrorArray[i].innerHTML = "Error - input field is blank";
                goForm = false;
            }           
        }
        if(goForm == true) form.submit();
    }
    function resetform(form){
        form.reset();
    }
</script>

Error reported by IE8 debugger: Expected ')' login.xml, line 29 character 30 (which is right after the first "form.length")

You need to disable output escaping explicitly.

http://www.w3.org/TR/xslt#disable-output-escaping

As Kyle note in the comments, in particular you need to

(1) remove the CDATA tags and

(2) insert <xsl:text disable-output-escaping="yes">&lt;</xsl:text> where you need the character not to be escaped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM