-1

我有下面的 XSLT,但是当它运行时,它会创建下面的 HTML。问题出在两张表上。根据LinesFOCXSLT,元素出现在第一个表中,而不是第二个表中。

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

应该在第二张桌子上,但由于某种原因,出现在第一张桌子上。

4

1 回答 1

0

在问题的当前状态下,无法确定发生了什么。两个最可能的原因是这些。

(1)输入(你没有显示)有

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

显示为 Lines 的子代,而不是 LinesFOC 的子代。

(2) 实际产生输出的样式表(正如 hr_117 和 Borodin 已经指出的那样,您没有显示)<xsl:for-each select="Order/Lines/LineItem">在您显示的样式表的位置具有(或等效)<xsl:for-each select="Order/LinesFOC/LineItem">

换句话说,您似乎正在查看错误的文件。

于 2013-06-05T18:34:18.997 回答