views:

75

answers:

2

I am working on a school project. It's an internet page with XML / XSLT. For the design we thought about an image fading effect in the background.

I made it as you can see and it works perfectly on IE7. But checking it in FF 3.6 throws some suspicious errors in firebug und does not work.

For example:

alert($('menu_bg').innerHTML);  

works when used with document ready / observe. But none of these work:

$('#menu_dots').append("content"); // jQuery
$('menu_dots').insert("content");  // prototype

The point is, that I do not understand, why everything works without XSLT in both browsers. But when I do the same with XSLT it breaks in FF.

http://nak.erline.eu/index.xml

same domain /js/_script.js

I thought the problem is jQuery based, that's why I started to translate it to prototype. On my half way I realized, that the problem still happens. That's why the code is still with jQuery (commented) and Prototype.

Have you an idea?

A: 

If you have to work with XSLT, the HTML DOM, XML and cross-browser functionality, I can highly recommend Sarissa. It will make working with Microsoft's hard and incompatible ActiveX DOM and all other W3C-based DOMs a lot easier.

The problem you are (likely, not necessarily) facing is that the resulting DOM objects do not belong to the same origin XML Documents, which is default DOM behavior. As a result, jQuery or Prototype cannot find the new elements. One workaround is to insert them as text and have them reparsed, but that's costly. There are other workarounds, but the easiest is probably to have a look at Sarissa and learn to use it. It's not hard and makes your code more readable. You'll find that Sarissa takes care of these and other subtleties so you can worry about more important things..

Abel
Hi abel, Thank you for your answer. I see what you mean. But the point is, the page have to work even without enabled javascript. (of course without animation and so on). It seems like Sarissa parses the xml and xsl file. But it has to be unobtrusive. Additionally, jQuery and Prototype is able to find and access the elements. Just not able to edit them.
Erkan
Well, here's a simple fact: you cannot use XSLT, or jQuery, or Prototype without JavaScript enabled. It sounds like you are using a PI (processing instruction) on top of your XML to process the XML through XSLT? If that is the case, think again, because that will only give you trouble, unfortunately. The implementation of `<?xml-stylesheet ` is very different between browsers, your pages will not be indexed properly by search engines and scripting will work only marginally. But perhaps I am wrong and this is not the way implement it? In that case: without JavaScript, it won't work anyway.
Abel
Thank you :)I'm using XSLT because we have to use it for a better mark.XSLT in our project ist used for template functionality.Additionally I want to give the page a plus, by giving it some animation. But as I said, the page should work without JS. Important is only, that it gives the same feeling on IE+7 and FF +3.2 .
Erkan
@Erkan: sorry, I didn't notice the link on your page and didn't see how you implemented it. Your current use of XSLT is indeed very hard and will give you many headaches. But if you must...
Abel
+1  A: 

At the top of your XSLT File change:

<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" />

to

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

Notice that the output method type should be html instead of xml. That fixed the problem in my tests.

I found the hint to the answer here: http://stackoverflow.com/questions/2687777/why-does-my-simple-strict-xhtml-file-give-errors-when-i-include-jquery

Also in my test, I removed the following script references

<script src="src/scriptaculous.js" type="text/javascript"/>
<script type="text/javascript" src="js/_script.js"/>

and added a reference to jQuery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>

and tested with your jQuery code snippet.

<script>
    $(document).ready(function(){
        $('#menu_dots').append("content");
    });
</script>
Brandon Boone
+1 voting this up because I think this is a better answer than mine :)
Abel
Hey, thank you! Geat answer and it woks.BUT, we have to validate the code generated by the XSLT by taking the html code out of firebug. The problem is, when I change the output method to HTML, it breaks the xhtml structure like:method: html : <img src="...">method: xml : <img src="..." />because we are using <html xmlns="http://www.w3.org/1999/xhtml"the validator require xml syntax.I could do it without xmlns="http://www.w3.org/1999/xhtml", but then the error is: no document type declaration; implying "<!DOCTYPE HTML SYSTEM>", because firebug is not printing the doctype ahead.
Erkan
Interesting, I wasn't aware that XSLT would alter the structure that you provide it. If I type "<img ... />" in my .xslt document, I would expect to get that exact syntax back (plus whatever XML I injected into the document). Also, Firebug may be altering the rendered text so that if fits nicely into it's DOM parser (tree view)??? But again, you said it changes based on the "method." So I'm not sure, but I'll post a follow up if I find anything on the subject.
Brandon Boone
That's exactly what i would expect from the xsl document. But it deletes the / from all tags.
Erkan
What happens if you explicitly declare all your tags? `<img src=""></img>`
Brandon Boone
it makes no difference whether i use <img></img> or <img/>. that's what it creates: <img src="...">. :)
Erkan