views:

359

answers:

5

Good day, I have stumbled upon a bug or some strange behaviour and I can't find the solution anywhere.

I use XSLT to display HTML from a XML document. Inside that stylehsheet, I use javascript/jQuery to add some contents. But apparently you can not append anything but texts to any container.

<script type="text/javascript">
<![CDATA[
 $(function() {
  $("div#topbanner" ).html('<img src="images/load-top.gif" class="load" />');
 });
]]>

It's working perfectly under Firefox but with IE7, after the codes execution, only the unrendered HTML appears into my DIV. Like if the <> got replaced by &gt; &lt; respectively.

To make it work under IE7, I must take out the CDATA tag but doing so, Firefox do not render it.

Is there a way to make the information into the html method execute as html code?

Thank you in advance

A: 

I've seen this when I forget to use

disable-output-escaping="yes"

in my <xslvalue-of../>

Keith
I heard about that function but where am I going to add it in my javascript?I want to be able to execute the javascript so I have to include it into CDATA tag but I need my Javascript/JQuery function to execute real HTML and not it's version with entities.I've googled a bit and it seems to be a known behaviour when using innerHTML into Javascript when its run into a XSLT stylesheet. But none has any solutions.Do you? :)Steve
I guess I don't understand then. Is it the jquery code (above) not working as expected, or is it the XSLT (not shown)? I was assuming the XSLT was rendering the > and <. Maybe more information/sample code is needed to answer your question?
Keith
A: 

The jQuery is working like expected but the html generated from the jQuery method html is shown as text and not rendered as HTML tag.

After executing:

$("div#topbanner" ).html('<img src="images/load-top.gif" class="load" />');

My div contains the string <img src="images/load-top.gif" class="load" /> and not the image itself.

I suspected it was because of the ![CDATA[ tag I use to wrap my javascript code.

Note that it's doing the expected behavior under IE7 WITHOUT the ![CDATA[ but not in Firefox. To make it work under Firefox, I must USE the ![CDATA[ but its no longer working with IE7.

I'm stuck between two browsers capabilities.

Help would be appreciated!

A: 

Embedded Javascript & XSLT = Insanity ;-)

The solution:

<script type="text/javascript">
    //<xsl:comment><![CDATA[
     $(function() {
      $("div#topbanner" ).html('<img src="images/load-top.gif" class="load" />');
     });
    //]]></xsl:comment>
</script>
Patrick
A: 

What happens if you try this?

<![CDATA[
 $(function() {
  $("<img>").addClass("load").attr("src","images/load-top.gif").appendTo("div#topbanner");
 });
]]>

or if that still doesn't work... try this method

<![CDATA[
 $(function() {
  myimg = new Image();
  $(myimg).addClass("load").attr("src","images/load-top.gif").appendTo("div#topbanner");
 });
]]>
fudgey
A: 

I have found a solution. I must keep my javascript in a external file.

Thank you to anyone who tried to help.

Steve Thomas