1

Okay, I did a crappy job of describing the issue in my previous post. I think the discussion got sidetracked from the core issue - so I'm going to try again. Mea Culpa to Elzo Valugi about the aforementioned thread.

I have an XML file:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="wtf.xsl"?>
<Paragraphs>
  <Paragraph>Hi</Paragraph>
</Paragraphs>

Simple enough. I also have a stylesheet to create XHTML output:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" 
            xmlns="http://www.w3.org/1999/xhtml"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml"
          indent="yes"
          doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
          doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
          omit-xml-declaration="yes"/>

  <xsl:template match="/*">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
        <title>FF-JS-XHTML WTF</title>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="wtf.js"></script>
      </head>
      <body>
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Paragraph">
    <p>
      <xsl:apply-templates />
    </p>
  </xsl:template>
</xsl:stylesheet>

Last but not least, I have the following jQuery in toto (wtf.js, from the script tag in the stylesheet):

$(function() {
    alert('Hiya!');
    $('<p>Hello</p>').appendTo('body');
});

Extremely simple, but sufficient for the demonstration. When I run this in Internet Explorer, I get the alert 'Hiya!' as well as the expected:

Hi

Hello

but when I run it in Firefox (3.0.1), I still get the alert, but the jQuery does not insert the paragraph into the DOM, and I just get this:

Hi

If I change the stylesheet to method="html" it works fine, and I get (along with the alert):

Hi

Hello

Why doesn't Firefox run the jQuery with an XHTML document? Has anyone any experience with this problem?

EDIT: ADDITIONAL INFO

I can successfully insert elements into the documents this way in Firefox (method="xml"):

var frag = document.createDocumentFragment();
var p = document.createElement('p');
p.appendChild(document.createTextNode('Ipsum Lorem'));
frag.appendChild(p);
$('body').append(frag);

but I'm running into a similar problem with the .remove() method.

It is looking more and more that Firefox doesn't construct a DOM from XML that jQuery can relate to, or somesuch.

0

3 Answers 3

1

I'm not very familiar with jQuery, but it looks to me like jQuery is using innerHTML to add the "Hello" fragment (jquery.1.3.2.js line 911) which won't work with XHTML.

4
  • @Alohci: Huzzah! Progress! Now... what jQuery statement would you use as an alternative? Is this even possible in jQuery? Figures it would work in IE6. Stupid crap browser... Jul 27, 2009 at 23:55
  • Frankly, I don't know what the level of support jQuery has for XHTML. I suggest you ask on one of the jQuery mailing lists. As for IE, it works because IE doesn't support XHTML as XML, it just treats it as normal HTML where, of course, "innerHTML" works just fine.
    – Alohci
    Jul 28, 2009 at 0:08
  • I was premature marking this as answered. Sorry. The innerHTML bit doesn't explain why I can use the append() method successfully when I create the node in a document fragment (see EDIT). Jul 29, 2009 at 16:58
  • Well, it looks like the purpose of the block of code starting at Line 871 and ending at 941 (i.e. including the innerHTML call) is to convert an HTML string to DOM nodes (at least that's what the comment says it does at line 871) so if you pass in a document fragment, then it's not going to have make the innerHTML call since the fragment is already a node.
    – Alohci
    Jul 29, 2009 at 19:16
0

Is it this issue? http://dev.jquery.com/ticket/4895 They suggest using xsl:output method="html" instead of xsl:output method="xml".

1
0

Try using

$.("body").text("<p>Hello</p>");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.