2013-06-05 64 views
-1

我有下面的XSLT,但是當它運行時,它會創建下面的HTML。問題在於兩張桌子。根據XSLT,LinesFOC元素顯示在第一個表格中,而不是第二個表格中。誰能告訴我爲什麼我生成的HTML不能用這個XSLT工作

<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="/"> 
    <html> 
     <body> 
     <h2>Order Received</h2> 
     <table border="1"> 
      <tr> 
      <th>Outlet</th> 
      <td><xsl:value-of select="Order/Outlet/Name"/></td> 
      </tr> 
      <tr> 
      <th>House Name/Number</th> 
      <td><xsl:value-of select="Order/Outlet/HouseNameNumber"/></td> 
      </tr> 
      <tr> 
      <th>Street Name</th> 
      <td><xsl:value-of select="Order/Outlet/Street1"/></td> 
      </tr> 
      <tr> 
      <th></th> 
      <td><xsl:value-of select="Order/Outlet/Street2"/></td> 
      </tr> 
      <tr> 
      <th></th> 
      <td><xsl:value-of select="Order/Outlet/Street3"/></td> 
      </tr> 
      <tr> 
      <th>Suburb</th> 
      <td><xsl:value-of select="Order/Outlet/Suburb"/></td> 
      </tr> 
      <tr> 
      <th>Town</th> 
      <td><xsl:value-of select="Order/Outlet/Town"/></td> 
      </tr> 
      <tr> 
      <th>County</th> 
      <td><xsl:value-of select="Order/Outlet/County"/></td> 
      </tr> 
      <tr> 
      <th>Postcode</th> 
      <td><xsl:value-of select="Order/Outlet/Postcode"/></td> 
      </tr> 
      <tr> 
      <th>Telephone Number</th> 
      <td><xsl:value-of select="Order/Outlet/TelephoneNumber"/></td> 
      </tr> 
      <tr> 
      <th>Contact Name</th> 
      <td><xsl:value-of select="Order/Outlet/ContactName"/></td> 
      </tr> 
      <tr> 
      <th>UWG Account Number</th> 
      <td><xsl:value-of select="Order/Outlet/UWGAccountNumber"/></td> 
      </tr> 
      <tr> 
      <th>Cash or Credit</th> 
      <td><xsl:value-of select="Order/Outlet/CashOrCredit"/></td> 
      </tr> 
      <tr> 
      <th>Order Date</th> 
      <td><xsl:value-of select="Order/Date"/></td> 
      </tr> 
      <tr bgcolor="#9acd32"> 
      <th>Qty</th> 
      <th>Description</th> 
      </tr> 

      <xsl:for-each select="Order/Lines/LineItem"> 
      <tr> 
       <td><xsl:value-of select="Qty"/></td> 
       <td><xsl:value-of select="Description"/></td> 
      </tr> 
      </xsl:for-each> 

     </table> 

     <table border="1"> 
      <tr bgcolor="#9acd32"> 
      <td></td> 
      <td>Free of Charge Items</td> 
      </tr> 
      <xsl:for-each select="Order/LinesFOC/LineItem"> 
      <tr> 
       <td><xsl:value-of select="Qty"/></td> 
       <td><xsl:value-of select="Description"/></td> 
      </tr> 
      </xsl:for-each> 
     </table> 

     </body> 
    </html> 
    </xsl:template> 

</xsl:stylesheet> 

生成的HTML是

<table class="MsoNormalTable" border="1" cellpadding="0"> 
    <tbody> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Outlet </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">Test Outlet 4</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>House Name/Number 
     </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">Test House</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Street Name </b> 
     </p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">Test Street</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"></td> 
     <td style="padding:.75pt .75pt .75pt .75pt"></td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"></td> 
     <td style="padding:.75pt .75pt .75pt .75pt"></td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Suburb </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">Testtown</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Town </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">Testtown</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>County </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">Cardiganshire</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Postcode </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">GU21 </p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Telephone Number 
     </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"></td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Contact Name </b> 
     </p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"></td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>UWG Account Number 
     </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">55555555555</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Cash or Credit </b> 
     </p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"></td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Order Date </b></p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">05/06/2013 00:00:00</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="background:yellowgreen; padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Qty</b></p> 
     </td> 
     <td style="background:yellowgreen; padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal" align="center" style="text-align:center"><b>Description</b></p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">3</p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal"> Chocolate 1L (110717)</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">3</p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal"> Strawberry 1L (110645)</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">3</p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal"> Banana 1L (110656)</p> 
     </td> 
    </tr> 
    <tr> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">3</p> 
     </td> 
     <td style="padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal"> Strawberry 1L (110645) </p> 
     </td> 
    </tr> 
    </tbody> 
</table> 

<p class="MsoNormal"><span style="">&nbsp;</span></p> 

<table class="MsoNormalTable" border="1" cellpadding="0"> 
    <tbody> 
    <tr> 
     <td style="background:yellowgreen; padding:.75pt .75pt .75pt .75pt"></td> 
     <td style="background:yellowgreen; padding:.75pt .75pt .75pt .75pt"> 
     <p class="MsoNormal">Free of Charge Items </p> 
     </td> 
    </tr> 
    </tbody> 
</table> 

第一個表的最後一個項目,是:

<tr> 
    <td style="padding:.75pt .75pt .75pt .75pt"> 
    <p class="MsoNormal">3</p> 
    </td> 
    <td style="padding:.75pt .75pt .75pt .75pt"> 
    <p class="MsoNormal"> Strawberry 1L (110645) </p> 
    </td> 
</tr> 

應該是第二個表,但由於某些原因,出現在第一張桌子。

+1

我不明白輸出與xlst有什麼關係。在我的這幾個xslt從未產生輸出。還需要輸入xml。 –

+2

您輸出的樣式表絕對不會生成此輸出。一方面,輸出'td'元素具有樣式表中沒有的'style'屬性。 – Borodin

回答

0

在問題的當前狀態中,無法確定發生了什麼事情。這兩個最可能的原因是這些。

(1)輸入(你不顯示)具有

<LineItem> 
    <Qty>3</Qty> 
    <Description> Strawberry 1L (110645) </Description> 
</LineItem> 

表現爲線條的孩子,而不是LinesFOC的孩子。 (2)實際產生輸出的樣式表(其中,hr_117和Borodin已經指出,你沒有顯示)具有<xsl:for-each select="Order/Lines/LineItem">(或等價物),其中顯示的樣式表具有<xsl:for-each select="Order/LinesFOC/LineItem">

換句話說,你似乎在看錯文件。

相關問題