Closed Bug 338721 Opened 18 years ago Closed 18 years ago

background to body is not applyed when XSLT is used

Categories

(Core :: XSLT, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: boen.robot, Unassigned)

Details

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3

Mozilla Firefox seems to be unable to put a background or background-color on the <body> element when XSLT is used. If plain XHTML&CSS is used, it all works, but not with XSLT.

Reproducible: Always

Steps to Reproduce:
1. Create some XML file (empty would work too) and link it to the XSLT stylesheet below.
2. Create an XSLT containg something like this (that's minimal testcase):
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Untitled Document</title>
		<style type="text/css">
		@import url("debug.css");
		</style>
	</head>
	<body>
		<div>Foo</div>
	</body>
</html>
</xsl:template>
</xsl:stylesheet>
3. Create a stylesheet called debug.css and save it to the same folder. Include background or background-color property for the body in your styling.
4. View the XML file with Mozilla Firefox 1.5.0.3.
Actual Results:  
There is no background[-color] on the body. Other styles are applyed correctly.

Expected Results:  
The body should have the background[-color] declared in the CSS stylesheet.

I tryed using the <link /> element in order to import the stylesheet, but the result is the same. I also tryed embeding the CSS into the XSLT, but no luck with that. Whitespace, CSS names, hexes, etc. isn't making a difference either.
And if you include the CSS directly in the XSLT (so not via a import or similar CSS rule) does it then work or not work? Can you paste the contents of debug.css here?
(In reply to comment #1)
> And if you include the CSS directly in the XSLT (so not via a import or similar
> CSS rule) does it then work or not work? Can you paste the contents of
> debug.css here?
> 

As I said in the additional comments part (the end) I tryed embeding the stylesheet (including directly inside the <style> element) into the XSLT but the result is the same. The content of debug.css could be anything you like as long as it contains this line:
body{background: #0000FF;}
or this one
body{background-color: #0000FF;}

I didn't however tryed something else though. Now that I did it, it works. Adding a class or an ID to the body and using it instead works. For example <body> becomes <body class="a"> and the css has something like
.a{background: #0000FF;}

So the problem is with the body selector when used in XSLT...
You havn't attached a testcase, so I can only guess what the problem is based on the partial information you've supplied. In the future, please attach a complete testcase (don't link or include in comments)

XSLT documents are rendered in standards mode. That means that if you want to apply a background to the document you have to apply it to the root of the document, not to the body-element.

So change:

body { background: #0000FF; }

to

html { background: #0000FF; }
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
If that doesn't work please reopen this bug and attach a testcase.
It containts everything involved. The XML to be previewed, it's XSLT and the CSS. You can find verbose comments in all of the files, that describe what (should) happen.
Comment on attachment 222843 [details]
All of the files, involved in the bug

By the way, scince when the body element is not allowed to have a background[-color]?
The reason this doesn't work as you want it to is that you're outputting XHTML rather than HTML.

HTML has a 'body fixup rule' which, among other things, says that background applied to the body element should apply to the background of the document. This is the behaviour you are requesting.

XHTML does not have this rule. If you want to style the background of XHTML and other XML dialects you need to apply background to the root of the document.

So if you just remove the namespace declaration on the <html> element things will work fine. I strongly recommend doing this anyway since the way you're adding the namespace attribute you're just going to output parts of the document as XHTML and other parts as HTML.

Additionally you request the output method to be HTML, using the <xsl:output> element, which should not be mixed with XHTML.

Another reason to use HTML rather than XHTML is that IE ignores the XHTML stuff and just treats everything as HTML. So you're going to have to deal with differences between behaviour in the two browsers otherwise.

If you really really want to use XHTML, move the xmlns attribute to the top of the stylesheet (i.e. to the xsl:stylesheet element). Change the <xsl:output> method to xml, or remove the element entierly. And then read up on the differences between XHTML and HTML in specs and tutorials.

Please mark this bug verified if these solutions work for you.
Before it's all considered "over" (that is what's meant by "verified", right? I'm not much into this whole Bugzilla system), I must say I still don't get it. I'm missing some part of the process.

How come XHTML Strict documents get their background and the same document when generated with XSLT doesn't?

I've tryed to add an XML prolog to an "oridnary" XHTML 1.1 document, save it with *.xhtml extension and set this meta:
<meta http-equiv="Content-type" content="text/xhtml+xml; charset=utf-8" />
to ensure I'm using "genuine" XHTML, but yet the background is applyed to the body (testcase?). I also tryed using the following output:
<xsl:output
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"/>
to emulate an "HTML compatible" XHTML 1.0 Strict in the XSLT and yet the body's background is not applyed.

The whole point is... If XHTML really defines that the background should be applyed to the <html> element instead (I wasn't able to find that rule in HTML 4 you spoke of) then shouldn't this mean that the XHTML 1.0 Strict/1.1 file should also not receive backgrounds on it's body?

What bothers me is the difference between two theoretically identical files in the same browser, not the behaviour/rule among different browsers o_0.
In order for an XHTML document to be parsed as an XHTML document, you need to serve it with an XML mimetype from the server. That means either using text/xml, application/xml, or preferably, application/xhtml+xml.

If you pass it as text/html it'll always be treated as HTML no matter what.

If you're using files from a local filesystem affect the mimetype using the fileextension. So using .xml or .xhtml to load the file as XHTML. As above, .html will always be treated as HTML no matter what.
Well, as I said, I tryed using the *.xhtml file extension. My computer's local server (you know... home installed Apache 2.2 and all) has the XHTML's MIME type too. I did looked into the server's configuration just incase though and found the application/xhtml+xml MIME type. Opps, so it's not text/xhtml+xml. Anyway...

Nevertheless with and without the meta tag set with the correct MIME type, even if the xhtml extension is used on the serevr (http://my_IP/example.xhtml) the body's background is still displayed. We're getting to a whole new bug here o_0.
Attached file xhtml file
I suspect you're doing something else wrong. Applying style to the body element of an xhtml doc only styles that node for me.
Hmmm... I don't know what happened earlyer. Firefox's cache maybe. Anyway, I created a new file instead of altering the old one and made a minimal testcase again with <style> styles and it worked... or should I say it didn't. The body didn't had it's background. Good. Issue out. I'm marking it as "VERIFIED", right? Thanks ^_^.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: