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 に答える