views:

49

answers:

2

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")

+1  A: 

If you are using the script in some html file, comment the CDATA instruction:

<script type="text/javascript" language="javascript">
//<![CDATA[
  ...
//]]>
</script>

If the script link is in some xml file: check this link. If you use CDATA, there should be no need for &lt;

By the way: there's no need for the language property in the script tag.

Here's a microsoft suggestion:

<xsl:comment>
  <![CDATA[ 
       ...
  ]]> 
</xsl:comment>

And here's another usefull link on the subject (bottom line: Do not use complex inline JavaScript in XSLT-generated web pages)

KooiInc
I don't quite see how that would help. The problem is that `for(i=0;i<form.length` is changed to `for(i=0;i<form.length`.
Kobi
I tried the commenting out the CDATA lines as suggested above and received the same error.
Kyle
A: 

You need to disable output escaping explicitly.

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

nullptr
Thanks! That worked perfectly. I just removed the CDATA tags and inserted "<xsl:text disable-output-escaping="yes"><</xsl:text>" wherever I needed the less than.
Kyle
I think there are better solutions.
KooiInc