最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery and XSLT - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question asked Oct 1, 2009 at 17:01 Steve ThomasSteve Thomas 1
  • "into the html method".. html method means the jQuery.html method. The equivalent of innerHTML – Steve Thomas Commented Oct 1, 2009 at 20:25
Add a ment  | 

4 Answers 4

Reset to default 2

Embedded Javascript & XSLT = Insanity ;-)

The solution:

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

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

Thank you to anyone who tried to help.

I've seen this when I forget to use

disable-output-escaping="yes"

in my <xslvalue-of../>

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");
 });
]]>
发布评论

评论列表(0)

  1. 暂无评论