XSLT在IE中可以工作,但在Chrome或Firefox中无法工作。

4

给定一个普通的nhibernate配置文件:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://localhost/xmlStylesheets/nhibernate.xsl"?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
    <property name="connection.connection_string">Data Source=MyDB;User ID=MyUser;Connection Lifetime=0;Enlist=false;Pooling=true;Max Pool Size=100;Min Pool Size=0;Incr Pool Size=5;Decr Pool Size=1;Statement Cache Size=100;</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <property name="use_outer_join">true</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

我为此创建了一个XSLT转换。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:h="urn:nhibernate-configuration-2.2">
  <xsl:template match="h:hibernate-configuration/h:session-factory">
    <html>
      <head>
        <title>Projects</title>
        <link rel="Stylesheet" type="text/css" 
              href="http://localhost/xmlStylesheets/xml.css" />
      </head>
      <body>
        <div id="container">
          <div class="content" id="settings">
            <xsl:value-of select="count(h:property)" /> properties
            <table class="grid">
              <thead>
                <tr>
                  <th>Property</th>
                  <th>Value</th>
                </tr>
              </thead>
              <tbody>
              <xsl:for-each select="h:property">
                <tr>
                  <td><xsl:value-of select="@name" /></td>
                  <td><xsl:value-of select="." /></td>
                </tr>
              </xsl:for-each>
              </tbody>
            </table>
          </div>
        </div>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

这在IE中可以正常工作,但在Chrome或Firefox中无法呈现。有什么想法是什么问题?
2个回答

5

为了使此功能正常工作,您的Web服务器应该返回正确的mime-type xsl样式表。

XSL FAQ中所指定的那样,Mozilla需要 text/xmlapplication/xml

看起来chrome也最好使用application/xml。详情请参阅此处

通常情况下,IE并不像其他浏览器一样挑剔,可以使用 text/xsl


有趣。我从未遇到过这样的问题,所以知道这可能是一个问题很好。谢谢! - Roland Bouman
1
另外,我直接浏览到了该文件。一旦我将其放在Web服务器上并修复了MIME类型,它就可以在非IE浏览器中正常工作。谢谢! - Tim Hoolihan
1
对我来说,text/xmlapplication/xml在Chrome中都无法正常工作。它只显示一个白屏。你能猜到原因吗? - Manish
@Manish - 猜猜看?Chrome有Bug吗?Chrome开发人员没有实现它?你需要问Chrome开发人员为什么它不起作用。 - Oded

1

在Opera 10.10、Chromium 4.0、Firefox 3.6和IE8中都可以很好地工作。我得到了这个输出:

8 properties
Property    Value
connection.provider NHibernate.Connection.DriverConnectionProvider
dialect NHibernate.Dialect.Oracle10gDialect
connection.driver_class NHibernate.Driver.OracleDataClientDriver
connection.connection_string    Data Source=MyDB;User ID=MyUser;Connection         Lifetime=0;Enlist=false;Pooling=true;Max Pool Size=100;Min Pool Size=0;Incr Pool Size=5;Decr Pool Size=1;Statement Cache Size=100;
proxyfactory.factory_class  NHibernate.ByteCode.Castle.ProxyFactoryFactory,         NHibernate.ByteCode.Castle
use_outer_join  true
query.substitutions true 1, false 0, yes 'Y', no 'N'
show_sql    true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接