1

我使用以下代码使用 XSLT 将 XML 文件显示为 HTML

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Report/Scripts">
<html>
   <head>
   <title>Mobiuss.rtp Test Execution Results</title>
   <link rel="stylesheet" href="xmlstyle.css" />
   </head>
   <body>
   <xsl:for-each select="Script">
   <h1><xsl:value-of select="@File"/></h1>
   Execution log
   <br>
   </br>
   <table class="sortable">
   <tr>
   <th>Time</th>
   <th>Position</th>
   <th>Type</th>
   <th>Message</th>
   </tr>
   <xsl:for-each select="Message">
   <tr>
   <td> <xsl:value-of select="@Time"/></td>
   <td>Line <xsl:value-of select="@Line"/></td>
   <td> <xsl:value-of select="@Type"/></td>
   <td> <xsl:value-of select="@Message"/></td>
   </tr>
   </xsl:for-each>
   </table>
   </xsl:for-each>       
   </body>
</html>   
</xsl:template>
</xsl:stylesheet>

上面的代码将 XML 文件显示为 html,它创建了大约 4 个表(取决于 XML)但由于某种原因,我不知道第一个表单独遵循 CSS,所有其他表都没有设置样式。

CSS代码在这里:

@CHARSET "ISO-8859-1";
.sortable {width:100%; height:40px; border:1px solid #ccc; background-color:#EEE0E5}
.sortable th {padding:4px 6px 6px; background:#444; color:#fff; text-align:center;     color:#ccc}
.sortable td {padding:2px 4px 4px; background:#fff; border-bottom:1px solid #ccc; overflow:auto}
.sortable .head {background:#444 url(images/sort.gif) 6px center no-repeat; cursor:pointer; padding-left:18px}
.sortable .desc {background:#222 url(images/desc.gif) 6px center no-repeat; cursor:pointer; padding-left:18px}
.sortable .asc {background:#222 url(images/asc.gif) 6px  center no-repeat; cursor:pointer; padding-left:18px}
.sortable .head:hover, .sortable .desc:hover, .sortable .asc:hover {color:#fff}
.sortable .even td {background:#f2f2f2}
.sortable .odd td {background:#fff}

请指导我在我的代码中进行哪些更改,以便创建的所有表格都具有正确的样式。

4

1 回答 1

0

所以这是一个简单的测试:http: //jsbin.com/azaqog/1/似乎工作正常。您所面临的问题在提供的数据中并不明显。

我现在可以怀疑的一件事是,您从 XML 解析的数据包含导致最终 HTML 无效的内容。我建议您将 XML+XSLT 解析为原始文本文件,然后查看输出。您应该在那里看到破坏您的 html 的东西。

于 2012-09-05T08:59:41.700 回答