views:

350

answers:

4

I have an XML file that references an XSL file (like ya do) that until lately has generated perfectly acceptable HTML output, regardless of browser.

A new requirement has come down from on high for XHTML output for compatibility with another product. Ok, fine - I reworked my stylesheet to produce (W3C Validated) XHTML.

Previously, I would open my XML file and view the transformed output just fine in IE and FF. Now, I get all kinds of troubles. IE6, 8 and 8-in-IE7 mode display a completely blank page. Firefox 3.5.1 displays just the text nodes, completely devoid of formatting. Firefox 3.0.1 displays the page (almost) normally - aside from a white border around the page and the JavaScript doesn't work.

Anyone know why? Here is the beginning of the XHTML output file:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC 
          "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:ftid="http://www.boeing.com/FTID-ML" 
      xmlns:rev="http://www.boeing.com/FTID-ML/Revision" 
      xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
+2  A: 

Having the XML declaration above the DOCTYPE forces IE6 into quirks mode, so that explains why it's not working properly in IE6. I can't speak for the other browsers. It might help to show us some more code.

jimyi
So... doesn't that invalidate the XHTML?
ScottSEA
Yep. Unfortunate, but the XML declaration is optional. What happens to the page rendering when you don't include it?
jimyi
Nothing. Still the same result.
ScottSEA
+1  A: 

Check that you're reporting correct content type in the HTTP response. Should be application/xhtml+xml

ykaganovich
How do I control this? I am only viewing XML files on the local hard drive, not through a server.
ScottSEA
hmm thinking about it, I'm not sure if that's correct if you're generating xhtml on the client side. But I guess one thing to try is to pregenerate the XHTML and see if it makes any difference for rendering.
ykaganovich
Did that - no luck. I tried renaming the file with various extensions (xml, xhtml, html) and got nowhere.
ScottSEA
IE doesn't understand application/xhtml+xml. Unfortunately, cross-browser support requires serving text/html.
eyelidlessness
+1  A: 
  • Check that your inline javascript/css is in a CDATA block (and not "commented out")
  • white border around page: XHTML doesn't treat the "html" element differently. You should set html { background-color: #f5f5f5; }, not body { background-color:#f5f5f5; }
  • check your content-type. older IEs don't support application/xhtml+xml at all, but want text/html
hhaamu
Content-type? how do I control that?
ScottSEA
In this case, it's a server setting. If you're testing files locally, that isn't the problem.
Ben Blank
+1  A: 

The problem, believe it or not, was my title element.

<title />

doesn't work. IE freaks out, loses it's little mind and doesn't display anything.

<title> </title>

cured the problem. Further information: IE is doing just fine having the XML declaration at the top...

ScottSEA
Yes, that make sense. Your XHTML is being treated as HTML where <title /> means the same as <title>. So everything after <title /> is being treated as part of the page title. This applies to all self closed elements, so you should ensure that only empty elements e.g. meta, br, input hr etc are self-closed in the stylesheet output.
Alohci
See also: http://stackoverflow.com/questions/637268/is-ie-the-only-web-browser-that-requires-script-script-and-hates-script andhttp://webkit.org/blog/68/understanding-html-xml-and-xhtml/
eyelidlessness
Regarding the XML declaration, it's not that IE can't read the document with it, it's that it will render in Quirks Mode, which is more or less the IE 5.5 engine. That means your CSS and such will be *wrong*.
eyelidlessness
The XML declaration still throws IE into quirks mode, which will make it harder (sometimes *much* harder) to make the appearance consistent across browsers. As it's always optional (as per the XML specs), you're better off without it.
Ben Blank
The fact that <title /> doesn't work but <title>...</title> does means that you're in quirks mode. That means that in order for it to display correctly, you will need to make your CSS and Javascript quirks-mode compliant rather than standard compliant. That means that strictly speaking you are not meeting the requirement "from on high". Don't know if anyone cares though :)
ykaganovich
"The fact that <title /> doesn't work but <title>...</title> does means that you're in quirks mode." Nope. Quirks vs Standards mode has nothing to do with this. "The XML declaration still throws IE into quirks mode" - This is only true of IE6.
Alohci
The fact that <title /> doesn't work by <title> ... </title> does means you are in HTML mode not XHTML mode. So you have to write your XHTML in a way that almost conforms with the HTML spec as well as conforming to the XHTML spec. http://www.w3.org/TR/xhtml-media-types/ (this is why I stick to HTML 4.01 on the client side - the cost (non-zero) outweighs the benefits (zero))
David Dorward
@Ykaganovich - I do indeed care very much. I went to great troubles to avoid quirks mode, so I shall definitely be removing the declaration. Thanks to all.
ScottSEA