2006-07-07

xsl和xslt文件扩展名的问题

以前为StudIP生成pdf文件接触过xsl,但是一直搞不太清楚为什么会有xsl和xslt两个不同的文件类型。在XML Spy中创建文件时也可以选择是创建xsl文件还是xslt文件。

如果选择创建xsl文件,则程序生成的文件头为:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
</xsl:stylesheet>

如果选择创建xslt文件,则程序生成的文件头为:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
</xsl:stylesheet>

可以看出,两者的差别主要在于后者多了一行:
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

另外后者在命名空间商业多出 xmlns:xs="http://www.w3.org/2001/XMLSchema" 。

xsl 的mail list上有人对此的回复是:
.xsl files usually contain XSLT and XSL-FO both. While .xslt files usually contain XSLT alone.

1 条评论:

  1. You should not (in general) assume any special semantics for any extension. For example on an ISO format CDROM you can't have .xslt at all. On my "home" ISP I can not use .xsl for XSLT files as they are served with a mime type of text/plain (and I can't change the mime type without paying money) so I serve XSLT files with .xml.

    On a web server the extension should _never_ have any effect (although IE does sometimes use this in non standard ways to override the specified mime type) the server sends an "HTTP header" along with the file, and this should explictly declare that the files are an XML mime type (eg application/xml or application/xml+xsl).

    On the filesystem, for local files the extension will have an effect, but you can not ask on a global group what that effect will be, it all depends on your local settings (in the registrary on windows, or the .mimetypes file on unix/linux). This will define a default mapping on your system between extensions and mime types (and possibly a default application)

    回复删除