-1

I'm having trouble finding a bug in my JavaScript code. It tells me a runtime error has occurred: Expected ')'

Here is the code:

<xsl:for-each select="./projects/project">                      
    <script LANGUAGE='Javascript'>                  
    x = 0;
    if(x == 0) {
        document.write("<td style="background-color:#76787A" ><xsl:value-of  select="weight"/></td>")
    }
    else
    {
        document.write("<td><xsl:value-of select="weight"/></td>")
    }
    </script>                       
</xsl:for-each>

What do you think?

2
  • I recognize the string problem,I fixed it but I still get the same error... :s Commented Aug 16, 2010 at 10:38
  • If you still get the same error then you haven't fixed the problem. However a different issue, if you use a Mozilla browser like Firefox, is that document.write in XSLT stylesheet generated HTML is not supported, see developer.mozilla.org/en/XSL_Transformations_in_Mozilla_FAQ Commented Aug 16, 2010 at 10:50

3 Answers 3

10

You are not escaping your strings properly. If you look closely, the syntax highlighting here on SO shows you the problem.

Use escaped \" or single quotes ' when using quotes inside a string.

document.write("<td style='background-color:#76787A' >
                <xsl:value-of  select='weight'/></td>")
Sign up to request clarification or add additional context in comments.

Comments

0

Look at your document.write calls. You have a string (inside the " ") that again has " " inside of it. To Javascript this means you are closing the string, then have nonsense text to javascript, then opening the string again, etc.... You need to escape your string with a backslash like this:

document.write("<td style=\"background-color:#76787A\" ><xsl:value-of  select=\"weight\"/></td>")
    }

Comments

0

You need to escape the quotes in the String, or they aren't in the strings but terminating them.

document.write("<td style=\"background-color:#76787A\" ><xsl:value-of  select=\"weight\"/></td>")

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.