Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IS JavaScript clashing with XSLT?

Status
Not open for further replies.

li70

Technical User
Mar 24, 2007
10
GB
Hi. Everyone
I’m using an xslt stylesheet to transform my xml document to an html doc. This task requires to include some pieces of JavaScript code in the <head> part of the target doc. unfortunately, xslt is unable to parse some of JavaScript signs and operators such as (&& - < - >= - ; and so on). Placing JavaScript code between <![CDATA[ and ]]> tags eliminates this issue but results in losing the functionality of JavaScript code. In addition, using symbols such as &lt instead of < turns us to parsing problem. Furthermore, using back slashes in front of "special" characters leads to parsing problem.
Any suggestions to sort out this issue

Your help is much appreciated
 
<![CDATA[ and ]]> tags eliminates this issue but results in losing the functionality of JavaScript code

That shouldn't be true. I put all my javascript code between cdata tags to take it out of validation and I never have a loss of functionality.





[monkey][snake] <.
 
Thanks monksnake
but in my case it doesn't work. here is my code. could you plz tell what is the roung with my code?
<html>
<head>
<script language="JavaScript">
<![CDATA[
function isvalid(){
var myelements=document.getElementsByTagName("input");
var counter=myelements.length
for (var i=0;i< counter;i++){
var para=myelements.value;
if (myelements.getAttribute("idnull")=='False'){
if (isEmpty(para)){
alert("please fill in the box !"+myelements.name)
return false
}
}
} //for
return true;
} //isvalid

function isEmpty(para){
var fieldname=para;
if (fieldname== null || fieldname == ""){
return true;
}
return false;
} // is Empty
]]>
</script>
</head>
<body>
<h4>
<i> All fields are required. </i>
</h4>
<form name="form1" method="GET" onSubmit="return isvalid()" >
id_card<input type="text" name="id_card" idnull="False"/>
<br/>
address<input type="text" name="address" idnull="False"/>
<br/>
d_of_birth<input type="text" name="d_of_birth" idnull="False"/>
<br/>
<input type="reset" value="Clear All Fields"/>
<input type="submit" VALUE="SUBMIT"/>
</form>
</body>
</html>
 
I'm sorry I believe I misunderstood your situation.

Could you post a little example of what you are running into? It'll help you get more replies, and I'd like to see what I can do to help.

[monkey][snake] <.
 
You need to comment out your CDATA statements, otherwise it is unknown to javascript. (Put /* */ around the opening and closing CDATA block.

Like this:

Code:
/*<![CDATA[*/ 

/*]]>*/



[monkey][snake] <.
 
Thanks alot monksnake
I got it. well done
cheers
 
hi.. again
So far so good, but what has derived me crazy is that why at run time the xslt processor weed out the <![DATA and ]]> from the target html document and just keep /**/. This is obvious by browsing the source code in the browser. And what surprise me is that the special JavaScript characters like ( < , > , &&) were converted into (&lt; , &amp;&amp;). As a result JavaScript code was frozen and the validation was escaped.
any clue?

Many thanks in advance
 
I recommend you post this question here: forum426

This question is more XML than javascript, and I'm not very knowledgable at XSLT.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top