1

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)

1
  • Good question, +1. See my answer, confirming that the issue is with google-chrome -- not with your code. :) Mar 7, 2011 at 2:05

2 Answers 2

1

Any ideas what im doing wrong?

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

2
  • Thanks. Looks like ill report a bug in Chrome then Mar 7, 2011 at 2:06
  • if anyone is interested, the bug is here Mar 7, 2011 at 2:45
0

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

1
  • Thanks. I ended up using a different approach to solve the problem, but I will keep this in mind for the future Nov 9, 2011 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.