0

我从 XSLT 输出中得到以下结果。我不想要结果中标题中的 InvoiceNo、InvoiceDate 和 DueDate。只需要带有 PC Quantity TotalAmount 的行,而不是第一行。

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>

我在做什么错?

问候, 米凯尔

4

1 回答 1

0

我的错。添加模板匹配后就可以了

于 2012-03-14T10:48:36.250 回答