What content-type should be used for XML+XSL presentation?
Asked Answered
S

4

13

I'm trying to render XML+XSL 2.0 in browser, returning .xml pages with application/xml content type and .xsl pages with text/xml. Safari is complaining for the main document: "Resource interpreted as document but transferred with MIME type application/xml." (but keeps rendering everything just fine).

I want to get rid of this warning message. What content-types should be used for the XML document?

Slinkman answered 16/7, 2011 at 6:23 Comment(3)
Does "XML+XSL 2.0" mean that you use XSLT 2.0? Is there any browser that supports XSLT 2.0?Lavalley
No browser support, but Saxon CE (alpha) provides XSLT 2.0 in the browser: saxonica.comZealot
Safari 5 and Chrome 15 work fine with XSLT 2.0 (on Mac)Slinkman
S
12

I've had success using text/xml with the stylesheet as text/xsl (or perhaps this is OK as text/xml as you have it working). text/xsl is widely recognized, but not "official" (as far as I understand it).

According to RFC 3023: "If an XML document that is, the unprocessed, source XML document is readable by casual users, text/xml is preferable to application/xml. MIME user agents (and web user agents) that do not have explicit support for text/xml will treat it as text/plain, for example, by displaying the XML MIME entity as plain text. application/xml is preferable when the XML MIME entity is unreadable by casual users."

See https://www.rfc-editor.org/rfc/rfc3023#page-16

Selfexistent answered 18/11, 2011 at 15:49 Comment(4)
text/xsl for an XML document??Slinkman
Sorry - for the stylesheet. And text/xml for the instance document.Selfexistent
According to RFC 3023: "If an XML document that is, the unprocessed, source XML document is readable by casual users, text/xml is preferable to application/xml. MIME user agents (and web user agents) that do not have explicit support for text/xml will treat it as text/plain, for example, by displaying the XML MIME entity as plain text.Application/xml is preferable when the XML MIME entity is unreadable by casual users." tools.ietf.org/html/rfc3023#page-16Selfexistent
Updated answer to reflect above comments.Selfexistent
R
9

Peeking into the WebKit source, it's easy to see what MIME types are considered valid for each resource type. It's not a very big list.

The following 4 MIME types are supported for "Documents":

  • text/html
  • text/xml
  • text/plain
  • application/xhtml+xml

There are only 2 valid types for stylesheets:

  • text/css
  • text/xsl

Obviously, the text/html, text/plain, and text/css types don't really apply here.

If you're really just interested in silencing the warnings, sending the .xml document as text/xml and the .xsl document as text/xsl should do the trick.

On the other hand, you concede that everything's rendering fine, so you might consider the "if it ain't broke, don't fix it" strategy.

Rhinoceros answered 23/11, 2011 at 16:27 Comment(0)
G
1

For what it's worth, the correct media type for XSLT would actually be application/xslt+xml, according to https://www.w3.org/TR/2007/REC-xslt20-20070123/#media-type-registration as per the official IANA registry https://www.iana.org/assignments/media-types/media-types.xhtml. And that's not new, the registration dates back to at least 2007. However, browser support for application/xslt+xml is almost non-existent.

Greyhound answered 30/12, 2019 at 16:4 Comment(0)
S
-3

Before any transformation i do this in PHP:

header("Content-Type: application/xhtml+xml; charset=utf-8");

the part with uft-8 is important ...

Steapsin answered 18/11, 2011 at 17:24 Comment(1)
That would apply if he did server-side transformation of XML to XHTML, and even then it would be problematic (IE/MSHTML does not support that MIME type). There is no "uft-8", but the "utf-8" in your code is only correct if the output actually is UTF-8-encoded. Which is not a requirement for XHTML. You did not answer the question.Claudclauddetta

© 2022 - 2024 — McMap. All rights reserved.