Chrome 中 XSLT 的意外结果
在我编写的程序中,部分 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
-
注意缺少的 和
标签
你知道我做错了什么吗? (对过长的帖子表示歉意)
In a program im writing, parts of the web interface are sent to the client as XML, and transformed into HTML fragments using Javascript and an XSLT. This works fine in Firefox (4.0b12) and Opera (10.63) but in Chrome (9.0.597.107) the results arn't as expected.
The 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>
The 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>
Expected Results (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>
Results in 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
-
Note the missing <tr>
and <td>
tags
Any ideas what im doing wrong?
(Apologies for the overly long post)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
什么都没有,除了可能使用有缺陷的 XSLT 处理器(无论 google-chrome 使用什么)。
我已使用以下九个不同的 XSLT(1.0 和 2.0)处理器测试了此转换,所有结果都是正确的:
MSXML 3,4,6
ALtova (XML SPY)
.NET(XslCompiledTransform 和 XslTransform)
Saxon(6.5.4 和 9.1.05)
XQSharp
Nothing, except perhaps using a buggy XSLT processor (whatever google-chrome uses).
I have tested this transformation with the following nine different XSLT (1.0 and 2.0) processors and the result from all of them is correct:
MSXML 3,4,6
ALtova (XML SPY)
.NET (XslCompiledTransform and XslTransform)
Saxon (6.5.4 and 9.1.05)
XQSharp
我刚刚遇到了同样的问题。
我猜问题是 chrome 验证 xslt 解析的输出并期望围绕 和 。如果你把你的 ' 放在周围,我认为问题就会解决(它对我有用......)
然后,如果你不需要它,你可以从结果中删除标签......
I just had the same issue.
I gues the problem is that chrome validates the output of the xslt parsing and expects a surrounding the and . If you put around your 's, I think the problem would be solved (it works for me...)
You can then strip the tag from the result if you don't need it...