【问题标题】:Unexpected results from XSLT in ChromeChrome 中 XSLT 的意外结果
【发布时间】:2011-12-14 18:35:15
【问题描述】:

在我正在编写的程序中,Web 界面的一部分以 XML 的形式发送到客户端,并使用 Javascript 和 XSLT 转换为 HTML 片段。这在 Firefox (4.0b12) 和 Opera (10.63) 中运行良好,但在 Chrome (9.0.597.107) 中结果与预期不符。

XSLT

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent ="yes"/>
  <xsl:template match ="/">
    <xsl:for-each select="queue/download">
      <xsl:choose>
        <xsl:when test="status='downloadError'">
          <xsl:variable name="rowClass">ui-state-error</xsl:variable>
          <xsl:variable name="iconClass">ui-icon ui-icon-alert</xsl:variable>
          <xsl:call-template name="download">
            <xsl:with-param name="iconClass" select="$iconClass"/>
            <xsl:with-param name="rowClass" select ="$rowClass"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="status='downloadRunning'">
          <xsl:variable name="rowClass">ui-state-highlight</xsl:variable>
          <xsl:variable name="iconClass">ui-icon ui-icon-refresh</xsl:variable>
          <xsl:call-template name="download">
            <xsl:with-param name="iconClass" select="$iconClass"/>
            <xsl:with-param name="rowClass" select ="$rowClass"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="status='downloadComplete'">
          <xsl:variable name="rowClass">downloadComplete</xsl:variable>
          <xsl:variable name="iconClass">ui-icon ui-icon-circle-check</xsl:variable>
          <xsl:call-template name="download">
            <xsl:with-param name="iconClass" select="$iconClass"/>
            <xsl:with-param name="rowClass" select ="$rowClass"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="rowClass" select ="status" />
          <xsl:variable name="iconClass"/>
          <xsl:call-template name="download">
            <xsl:with-param name="iconClass" select="$iconClass"/>
            <xsl:with-param name="rowClass" select ="$rowClass"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>

    </xsl:for-each>
  </xsl:template>

  <xsl:template name="download">
    <xsl:param name="rowClass"/>
    <xsl:param name="iconClass" />
    <xsl:variable name="id" select ="id"/>
    <xsl:variable name="filename" select ="filename"/>
    <xsl:variable name="comment" select ="comment"/>
    <tr class="{$rowClass}">
      <td class="downloadCheck">
        <input type="checkbox" class="downloadCheckbox" value="{$id}" name="downloadCheckbox"/>
      </td>
      <td class="downloadIcon">
        <span class="{$iconClass}"></span>
      </td>
      <td class="downloadName">
        <a href="#" onclick="showDownloadCommentBox('{$id}','{$filename}', '{$comment}');">
          <xsl:value-of select="filename"/>
        </a>
      </td>
      <xsl:if test="status='downloadError'">
        <td class="dError" colspan="4">
          <xsl:value-of select ="errortext"/>
        </td>
      </xsl:if>
      <xsl:if test ="status!='downloadError'">
        <xsl:variable name="progress" select ="progress"/>
        <td class="downloadProgress">
          <div class="jqProgress" value="{$progress}"></div>
        </td>
        <td class="downloadTimeLeft">
          <xsl:value-of select ="timeremaining"/>
        </td>
        <td class="downloadSize">
          <xsl:value-of select ="size"/>
        </td>
        <td class="downloadSpeed">
          <xsl:value-of select ="speed"/>
        </td>
      </xsl:if>
    </tr>
  </xsl:template>
</xsl:stylesheet>

XML

<queue>
   <name>test</name>
   <renderer>downloadQueue</renderer>
   <xsl>/xslt/downloadQueue.xslt</xsl>
   <status>suspended</status>
   <startMode>manual</startMode>
   <downloadDirectory>C:\Users\William\Programming\SCRAMDownloader\Trunk\bin\</downloadDirectory>
   <download>
       <filename>test.zip</filename>
       <progress>0.00%</progress>
       <speed>-</speed>
       <timeremaining>-</timeremaining>
       <status>downloadSuspended</status>
       <size>119.68 MB</size>
       <id>8976170e-1f4b-4b79-8901-5a4191e2c07d</id>
       <comment/>
   </download>
</queue>

预期结果 (Firefox)

<tr class="downloadSuspended">
    <td class="downloadCheck"><input type="checkbox" class="downloadCheckbox" value="8976170e-1f4b-4b79-8901-5a4191e2c07d" name="downloadCheckbox"></td>
    <td class="downloadIcon"><span class=""></span></td>
    <td class="downloadName"><a href="#" onclick="showDownloadCommentBox('8976170e-1f4b-4b79-8901-5a4191e2c07d','test.zip', '');">test.zip</a></td>
    <td class="downloadProgress"><div class="jqProgress ui-progressbar ui-widget ui-widget-content ui-corner-all" value="0.00%" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="ui-progressbar-value ui-widget-header ui-corner-left" style="width: 0%;"></div></div></td>
    <td class="downloadTimeLeft">-</td>
    <td class="downloadSize">119.68 MB</td>
    <td class="downloadSpeed">-</td>
</tr>

Chrome 中的结果

<input type="checkbox" class="downloadCheckbox" value="8976170e-1f4b-4b79-8901-5a4191e2c07d" name="downloadCheckbox">
<span class=""></span>
<a href="#" onclick="showDownloadCommentBox('8976170e-1f4b-4b79-8901-5a4191e2c07d','test.zip', '');">test.zip</a>
<div class="jqProgress ui-progressbar ui-widget ui-widget-content ui-corner-all" value="0.00%" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="ui-progressbar-value ui-widget-header ui-corner-left" style="width: 0%; "></div></div>
-
119.68 MB
-

注意缺少的&lt;tr&gt; 和&lt;td&gt; 标签

任何想法我做错了什么? (抱歉帖子过长)

【问题讨论】:

  • 好问题,+1。请参阅我的回答,确认问题出在 google-chrome 上,而不是您的代码上。 :)

标签: google-chrome xslt


【解决方案1】:

任何想法我做错了什么?

什么都没有,除了可能使用有问题的 XSLT 处理器(无论 google-chrome 使用什么)。

我已经用以下九种不同的 XSLT(1.0 和 2.0)处理器测试了这种转换,所有这些处理器的结果都是正确的:

  • MSXML 3,4,6

  • ALtova (XML SPY)

  • .NET(XslCompiledTransform 和 XslTransform)

  • 撒克逊人(6.5.4 和 9.1.05)

  • XQSharp

【讨论】:

  • 谢谢。看起来我在 Chrome 中报告了一个错误
  • 如果有人感兴趣,bug 是here
【解决方案2】:

我也遇到了同样的问题。 我猜问题是 chrome 验证了 xslt 解析的输出,并期望在 and 周围有一个 .如果你把你的 's 放在周围,我认为问题会得到解决(它对我有用......)

如果不需要,您可以从结果中删除标签...

【讨论】:

  • 谢谢。我最终使用了不同的方法来解决问题,但我会牢记这一点以备不时之需
猜你喜欢
  • 2019-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多