1

I've got a script in an XSL document and it's throwing an error when I try and use the javascript AND operator (&&).

if (input1=="" && input2==""){
    alert ("test");
}

The error that comes up is: XML Parsing Error: not well-formed and it points to the && operator.

How can I get around this?

2
  • 3
    I think you have to used &: input1=="" && input2=="". Commented Mar 20, 2015 at 22:25
  • have you considered defer="true" in your script tag? <SCRIPT LANGUAGE="javascript" DEFER="true"> Commented Mar 20, 2015 at 23:02

1 Answer 1

2

If you are writing XSLT then you are writing an XML document and your XSLT code needs to be well-formed XML. So either escape the ampersands as &amp;&amp; or use a CDATA section

<script><![CDATA[
if (input1 == "" && input2 == "") { 
  alert("test"); 
}
]]></script>

If you are trying to create HTML or SVG with script elements in your XSLT then of course a third option is to make use of external scripts e.g. to put your Javascript code into a .js file and to reference it as <script src="file.js"></script>, that way you don't have to take any efforts to escape script code according to XML rules.

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.