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

NEW
Unassigned

Status

()

Core
XSLT
10 years ago
10 years ago

People

(Reporter: Greg K., Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Reporter)

Description

10 years ago
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).
(Reporter)

Comment 1

10 years ago
Created attachment 343186 [details]
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.
(Reporter)

Comment 2

10 years ago
Created attachment 343187 [details]
Minimal XML example which links to the XSLT testcase
(Reporter)

Updated

10 years ago
Attachment #343186 - Attachment mime type: application/xslt+xml → text/xsl
(Reporter)

Comment 3

10 years ago
(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.
(Reporter)

Comment 5

10 years ago
(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/
You need to log in before you can comment on or make changes to this bug.