Open Bug 459999 Opened 16 years ago Updated 2 years ago

Firefox fails to apply CSS rules contained in a comment generated by an XSLT comment element

Categories

(Core :: XSLT, defect)

x86
Windows XP
defect

Tracking

()

People

(Reporter: bugmail, Unassigned)

Details

Attachments

(2 files)

When XSLT is used to transform XML into HTML (output method="html") and a Style element is generated containing CSS rules wrapped by comment tags, Firefox does not apply those CSS rules to the HTML content.

For example, in the following brief example, the paragraph will not be green.

<style type="text/css"><!-- p { color: green; } --></style>
<p>P</p>

This bug is not evident in WebKit (Safari 3.1.2 (525.21)) or Opera 9.60 (10447).
Attached file XSLT testcase
Testcase which displays FAIL when the CSS in the xsl:comment element is not used by the browser, and PASS when it is used. Safari 5.1.2 and Opera 9.60 both pass this test, while Firefox 3.0.3 fails it.
Attachment #343186 - Attachment mime type: application/xslt+xml → text/xsl
(In reply to comment #1)

> ...Safari 5.1.2...

That should be Safari 3.1.2. Also, the testcase also passes in IE 7.0.5730.13.
Attachment #343186 - Attachment mime type: text/xsl → application/xml
When you write
<style type="text/css"><!-- p { color: green; } --></style>

in HTML that does not actually create a comment node. It creates a text node that contains the characters '<!--' at the start and '-->' at the end. (You can check this by inspecting the DOM using javascript or firebug). This is defined by the HTML4 spec (iirc).

XSLT generates a DOM, which means that when you use <xsl:comment> it does in fact generate a real comment node. This is defined by the XSLT spec.

Comment nodes are generally ignored. And they are always ignored inside for example <style> and <script> elements. This is defined by HTML5.


In mozilla we take the outputted DOM from XSLT and display it directly. This means that there is a comment tag which is ignored.

Most other browsers serialize the DOM and then reparse it as HTML. This means that the comment is serialized with '<!--' and '-->' but then reparsed as a text node.

There is no spec that defines if displaying the DOM directly, or serializing and reparsing is the correct thing to do. So it is unclear what the correct thing to do is.


Let me ask you this: Why do you put a comment around your stylesheet? The comment thing was originally suggested for browsers that don't support the <style> tag and thus displayed its contents. I am not sure if there are any such browsers any more (note that you don't have to support CSS to support the style tag). And there are definitely no browsers that support XSLT but do support CSS.

So I'd recommend simply removing the comment.
(In reply to comment #4)
There is no spec that defines if displaying the DOM directly, or serializing
> and reparsing is the correct thing to do. So it is unclear what the correct
> thing to do is.

Who should we ask?

> Let me ask you this: Why do you put a comment around your stylesheet? The
> comment thing was originally suggested for browsers that don't support the
> <style> tag and thus displayed its contents. I am not sure if there are any
> such browsers any more (note that you don't have to support CSS to support the
> style tag). And there are definitely no browsers that support XSLT but do
> support CSS.

I have no such need. I encountered this scenario during testing. I agree it's unnecessary to comment style element content, but I'm surprised Mozilla operates uniquely among modern browsers.
(In reply to comment #5)
> (In reply to comment #4)
> There is no spec that defines if displaying the DOM directly, or serializing
> > and reparsing is the correct thing to do. So it is unclear what the correct
> > thing to do is.
> 
> Who should we ask?

Good question. I'd start with the XSL WG here:
http://lists.w3.org/Archives/Public/public-qt-comments/
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: