XSLT 适用于 IE,不适用于 Chrome 或 Firefox [英] XSLT works in IE, not in Chrome or Firefox

查看:52
本文介绍了XSLT 适用于 IE,不适用于 Chrome 或 Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<?xml-stylesheet type="text/xsl" href="http://localhost/xmlStylesheets/nhibernate.xsl"?><hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"><会话工厂><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"><头><title>项目</title><link rel="样式表" type="text/css"href="http://localhost/xmlStylesheets/xml.css"/><身体><div id="容器"><div class="content" id="settings"><xsl:value-of select="count(h:property)"/>特性<表格类=网格"><头><tr><th>财产</th><th>值</th></tr></thead><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>

</xsl:模板></xsl:stylesheet>

这在 IE 中工作正常,但不会在 chrome 或 firefox 中呈现.任何想法是什么问题?

解决方案

您的网络服务器应该为 xsl 表返回正确的 MIME 类型,以使其正常工作.

Mozilla 需要 text/xmlapplication/xml,如 XSL 常见问题.

看起来 chrome 会最佳服务 也带有 application/xml.

正如很多次一样,IE 并不像其他浏览器那样挑剔,并且对 text/xsl 感到满意.

Given a normal nhibernate config file:

<?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>

I created a xslt transformation for it.

<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>

This works fine in IE, but won't render in chrome or firefox. Any ideas what the issue is?

解决方案

Your webserver should be returning the correct mime-type for the xsl sheet for this to work.

Mozilla requires text/xml or application/xml, as specified in the XSL FAQ.

It would appear that chrome would be best served with application/xml too.

As is the case many times, IE is not as fussy as other browsers and is happy with text/xsl.

这篇关于XSLT 适用于 IE,不适用于 Chrome 或 Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆