开发者

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

开发者 https://www.devze.com 2023-03-20 13:44 出处:网络
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: \"Resourc

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?


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


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.


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.


Before any transformation i do this in PHP:

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

the part with uft-8 is important ...

0

精彩评论

暂无评论...
验证码 换一张
取 消