【问题标题】:Rendering XML with inline styles WITH OTHER FILE EXTENSION works in Firefox, but not Chrome. How to let chrome render XML with other file extension?使用带有其他文件扩展的内联样式呈现 XML 在 Firefox 中有效,但在 Chrome 中无效。如何让 chrome 使用其他文件扩展名呈现 XML?
【发布时间】:2019-10-29 00:27:42
【问题描述】:

我一直致力于使用本地 XSLT 呈现本地 XML。我通过使用内联样式表解决了这个问题(在谷歌搜索的帮助下)。所以我的 xml 被 Firefox 和 Chrome 漂亮地渲染了。

但如果我将文件扩展名从 .xml 更改为 .aml 之类的其他名称,Firefox 仍会呈现该文件,但 Chrome 不再呈现。 Chrome 只是在标签中以纯文本形式给出文件内容。

我的问题是,如何让 Chrome 渲染本地 xml 文件和其他扩展?

这是我的文件内容(此代码是在互联网上找到的,并非来自我,仅作为示例):

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
id ID #REQUIRED>
]>
<doc>
 <!--Start XSL-->
 <xsl:stylesheet id="stylesheet"
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

  <xsl:template match="xsl:stylesheet" />

   <!--Variables-->
   <xsl:variable name="a" select="/doc/list/movie/seen[@value ='Yes']" />
   <xsl:variable name="b" select="/doc/list/movie/seen" />
   <xsl:variable name="c" select="sum(/doc/list/movie/rating/@value)" />
   <xsl:variable name="d" select="$c div count($a)" />
   <xsl:variable name="e" select="count($a) div count($b)" />
   <xsl:variable name="f" select="/doc/list/movie/seen[@value ='No']" />
   <xsl:variable name="g" select="/doc/list/movie/seen[@value ='Prior']" />
   <xsl:variable name="h" select="count($f) div count($b)" />
   <xsl:variable name="j" select="count($g) div count($b)" />
   <xsl:variable name="minutes_total" select="sum(/doc/list/movie/length[@value ='y'])" />
   <xsl:variable name="minutes" select="$minutes_total mod 60" />
   <xsl:variable name="hours" select="floor($minutes_total div 60) mod 24" />
   <xsl:variable name="hours2" select="floor($minutes_total div 60)" />
   <xsl:variable name="days" select="floor($hours2 div 24)" />
   <!--End Variables-->

  <xsl:decimal-format name="percent" />
  <xsl:decimal-format name="average" decimal-separator="." />

  <xsl:template match="/doc">
   <html>
    <head>
     <style>
      h2{
      font-family: Courier, Courier New, monospace;
      font-size: 32px;
      text-decoration: underline;
      }
      body{
      font-family: Courier New, monospace;
      }
      p{
      font-size: 16px;
      }
      table{
      font-size: 14px;
      }
      .title{
      text-align:left;
      }
      .release{
      text-align:center;
      }
      .seen{
      text-align:center;
      }
      .rating{
      text-align:right;
      }
      .length{
      text-align:center;
      }
     </style>
    </head>
    <body>
     <h2>My Movie List</h2>
     <p>Movies seen so far: <xsl:value-of select="count($a)" />/<xsl:value-of select="count($b)" /> = <xsl:value-of select="format-number($e, '#%', 'percent')" /><br />
     Movies yet to see: <xsl:value-of select="count($f)" />/<xsl:value-of select="count($b)" /> = <xsl:value-of select="format-number($h, '#%', 'percent')" /><br />
     Movies seen prior to making list: <xsl:value-of select="count($g)" />/<xsl:value-of select="count($b)" /> = <xsl:value-of select="format-number($j, '#%', 'percent')" /><br />
     Total time watched: <xsl:value-of select="format-number($days, '#0')" /> days, <xsl:value-of select="format-number($hours, '#0')" /> hours, <xsl:value-of select="format-number($minutes, '#0')" /> minutes<br />
     Average rating:  <xsl:value-of select="format-number($d, '#.000', 'average')" /> stars out of 5</p>
     <br />
     <table border="1">
      <tr>
       <th>#</th>
       <th>Title</th>
       <th>Release Date</th>
       <th>Length</th>
       <th>Seen</th>
       <th>Rating</th>
      </tr>
      <xsl:for-each select="list/movie">
       <xsl:choose>
        <xsl:when test='seen = "Yes"'>
         <tr style="background-color:#666; color:#fff">
          <td> <xsl:number /></td>
          <td class="title"><xsl:value-of select="title"/></td>
          <td class="release"><xsl:value-of select="release"/></td>
          <td class="length"><xsl:value-of select="length" /> minutes</td>
          <td class="seen"><xsl:value-of select="seen"/></td>
          <td class="rating"><xsl:value-of select="rating"/></td>
         </tr>
        </xsl:when>
        <xsl:when test='seen = "Seen prior to making list"'>
         <tr style="background-color:#999; color:#000">
          <td> <xsl:number /></td>
          <td class="title"><xsl:value-of select="title"/></td>
          <td class="release"><xsl:value-of select="release"/></td>
          <td class="length"><xsl:value-of select="length"/> minutes</td>
          <td class="seen"><xsl:value-of select="seen"/></td>
          <td class="rating"><xsl:value-of select="rating"/></td>
         </tr>
        </xsl:when>
        <xsl:otherwise>
         <tr style="background-color:#fff;">
          <td> <xsl:number /></td>
          <td class="title"><xsl:value-of select="title"/></td>
          <td class="release"><xsl:value-of select="release"/></td>
          <td class="length"><xsl:value-of select="length" /> minutes</td>
          <td class="seen"><xsl:value-of select="seen"/></td>
          <td class="rating"><xsl:value-of select="rating"/></td>
         </tr>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:for-each>
     </table>
    </body>
   </html>
  </xsl:template>
 </xsl:stylesheet>

 <!--Start XML-->
 <list>
  <movie>
   <title>2001: A Space Odyssey</title>
   <release>1968</release>
   <seen value="No">No</seen>
   <rating>N/A</rating>
   <length value="n">141</length>
  </movie>
  <movie>
   <title>28 Days Later</title>
   <release>2002</release>
   <seen value="No">No</seen>
   <rating>N/A</rating>
   <length value="n">113</length>
  </movie>
  <movie>
   <title>28 Weeks Later</title>
   <release>2007</release>
   <seen value="No">No</seen>
   <rating>N/A</rating>
   <length value="n">100</length>
  </movie>
  <movie>
   <title>A Clockwork Orange</title>
   <release>1971</release>
   <seen value="Yes">Yes</seen>
   <rating value="2">&#9734;&#9734;&#9734;&#9733;&#9733;</rating>
   <length value="y">136</length>
  </movie>
  <!--Rest of XML-->
 </list>
</doc>

【问题讨论】:

    标签: xml google-chrome render local


    【解决方案1】:

    解决了。

    Chrome 使用系统范围的 mime 类型数据库。

    所以注册例如".aml" 作为 "application/xml" 可以解决问题。

    【讨论】:

      猜你喜欢
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      相关资源
      最近更新 更多