我有下面的XSLT,但是当它运行时,它会创建下面的HTML。问题出在两个表格上。根据XSLT,LinesFOC
元素出现在第一个表而不是第二个表中。
<?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=""> </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>
应位于第二个表格中,但出于某种原因,会出现在第一个表格中。
答案 0 :(得分: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">
(或等价物),你显示的样式表有{{1 }}
换句话说,您似乎在查看错误的文件。