0
我從XSLT輸出中得到以下結果。我不想從結果中的標題得到InvoiceNo,InvoiceDate和DueDate。只需要PC Quantity TotalAmount,而不是第一行。不要在XSLT 1.0中使用sum函數在「Group By」中擺脫「標題」
359970000018 2012-03-06 2012-04-05
PC Quantity TotalAmount
- 1 31.99
PC Quantity TotalAmount
100 4 1948.76
PC Quantity TotalAmount
200 2 974.38
我的xml文件看起來像這樣。
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="invoice.xslt"?>
<BONInvoice>
<Invoice>
<InvoiceNo>359970000018</InvoiceNo>
<Header>
<InvoiceDate>2012-03-06</InvoiceDate>
<DueDate>2012-04-05</DueDate>
</Header>
<Details>
<Detail>
<LineNo>1</LineNo>
<LineTotInclTax>31.99</LineTotInclTax>
<Products>
<SellerProductCode>SALESCOST</SellerProductCode>
<Quantity>1.00</Quantity>
</Products>
<Bespoke>
<FreeText>-</FreeText>
</Bespoke>
</Detail>
<Detail>
<LineNo>2</LineNo>
<LineTotInclTax>857.38</LineTotInclTax>
<Products>
<SellerProductCode>LEASINGCOST</SellerProductCode>
<Quantity>1.00</Quantity>
</Products>
<Bespoke>
<FreeText>100</FreeText>
</Bespoke>
</Detail>
<Detail>
<LineNo>3</LineNo>
<LineTotInclTax>117.00</LineTotInclTax>
<Products>
<SellerProductCode>LEASINGRENT</SellerProductCode>
<Quantity>1.00</Quantity>
</Products>
<Bespoke>
<FreeText>100</FreeText>
</Bespoke>
</Detail>
<Detail>
<LineNo>4</LineNo>
<LineTotInclTax>857.38</LineTotInclTax>
<Products>
<SellerProductCode>LEASINGCOST</SellerProductCode>
<Quantity>1.00</Quantity>
</Products>
<Bespoke>
<FreeText>100</FreeText>
</Bespoke>
</Detail>
<Detail>
<LineNo>5</LineNo>
<LineTotInclTax>117.00</LineTotInclTax>
<Products>
<SellerProductCode>LEASINGRENT</SellerProductCode>
<Quantity>1.00</Quantity>
</Products>
<Bespoke>
<FreeText>100</FreeText>
</Bespoke>
</Detail>
<Detail>
<LineNo>6</LineNo>
<LineTotInclTax>857.38</LineTotInclTax>
<Products>
<SellerProductCode>LEASINGCOST</SellerProductCode>
<Quantity>1.00</Quantity>
</Products>
<Bespoke>
<FreeText>200</FreeText>
</Bespoke>
</Detail>
<Detail>
<LineNo>7</LineNo>
<LineTotInclTax>117.00</LineTotInclTax>
<Products>
<SellerProductCode>LEASINGRENT</SellerProductCode>
<Quantity>1.00</Quantity>
</Products>
<Bespoke>
<FreeText>200</FreeText>
</Bespoke>
</Detail>
<Summary>
<TotalExclTax>2923.14</TotalExclTax>
<TotalTax>0.00</TotalTax>
<InvDiscPct>0.00</InvDiscPct>
<InvDiscAmount>0.00</InvDiscAmount>
<TotalInclTax>2923.00</TotalInclTax>
</Summary>
</Details>
</Invoice>
</BONInvoice>
和我的XSLT文件一樣。
<xsl:key name="costc" match="Detail" use="Bespoke/FreeText"/>
<xsl:template match="Details">
<xsl:apply-templates select="Detail[generate-id() = generate-id(key('costc', Bespoke/FreeText)[1])]" mode="Cost">
<xsl:sort select="Bespoke/FreeText" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Detail" mode="Cost">
<h1>
<!--PC <xsl:value-of select="Bespoke/FreeText" />-->
</h1>
<table>
<tr>
<td>PC</td>
<td>Quantity</td>
<td>TotalAmount</td>
</tr>
<xsl:apply-templates select="../Detail[Bespoke/FreeText = current()/Bespoke/FreeText][generate-id() = generate-id(key('costc',Bespoke/FreeText)[1])]" mode="Product" />
</table>
</xsl:template>
<xsl:template match="Detail" mode="Product">
<tr>
<td>
<xsl:value-of select="Bespoke/FreeText" />
</td>
<td>
<xsl:value-of select="sum(key('costc', Bespoke/FreeText)//Quantity)" />
</td>
<td>
<xsl:value-of select="sum(key('costc', Bespoke/FreeText)/LineTotInclTax)" />
</td>
</tr>
</xsl:template>
什麼是我做錯了嗎?
問候, 的Mikael
我找到了故障。我對XSLT相當陌生,並不瞭解xsl:template match的必需用法。 我現在已將以下內容添加到XSLT中, –
user1200589
2012-03-14 10:46:30