2012-03-13 12 views
0

XSLT出力から次の結果が得られます。 InvoiceNo、InvoiceDate、DueDateを結果のヘッダーから削除したくありません。最初の行ではなく、PC Quantity TotalAmountの行だけが必要です。XSLT 1.0の "Group By"で "header"を削除しないでください。

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 

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

私が間違って何をやってるのですか?

よろしく、 ミカエル

+0

私はこの欠陥を見つけます。私はXSLTを初めて学びましたが、xsl:template matchの必要な使い方を理解していませんでした。 XSLTに次のコードを追加しました。 /> – user1200589

答えて

0

私のミス。テンプレートマッチを追加した後の作業です

関連する問題