2012-06-06 148 views
3

我需要使用特定節點消除XML中的重複元素(ItemID)使用XSLT刪除重複元素

My XML看起來如下;

<XML> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>723073</ItemID> 
     <ColorID>02</ColorID> 
     <Description>Pentel LR7 Energel Metal Tip Refill 0.7mm</Description> 
     <MainCategory>WRITING INSTRUMENTS</MainCategory> 
     <SubCategory>Refill</SubCategory> 
     <LineNum>    1.0000000</LineNum> 
     <Qty>    6.0000000</Qty> 
     <UnitPriceExclTax>    10.0200000</UnitPriceExclTax> 
     <LineTax>    8.4200000</LineTax> 
     <LinePriceExclTax>    60.1200000</LinePriceExclTax> 
     <ColorName>Black</ColorName> 
     <UOM>EA</UOM> 
     <Backorder>    0.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637542_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>903420</ItemID> 
     <ColorID /> 
     <Description>STEPHENS JUNIOR Stapler Half Strip KW586</Description> 
     <MainCategory>OFFICE SUNDRIES</MainCategory> 
     <SubCategory>Staplers</SubCategory> 
     <LineNum>    2.0000000</LineNum> 
     <Qty>    3.0000000</Qty> 
     <UnitPriceExclTax>    32.2500000</UnitPriceExclTax> 
     <LineTax>    13.5400000</LineTax> 
     <LinePriceExclTax>    96.7500000</LinePriceExclTax> 
     <ColorName /> 
     <UOM>Ea</UOM> 
     <Backorder>    0.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637547_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>867241</ItemID> 
     <ColorID /> 
     <Description>TRODAT PRINTY S/Inking Stamp Copy 4911</Description> 
     <MainCategory>STAMPS DATERS NUMBERERS</MainCategory> 
     <SubCategory>Self Inking Stamps</SubCategory> 
     <LineNum>    3.0000000</LineNum> 
     <Qty>    1.0000000</Qty> 
     <UnitPriceExclTax>    42.1500000</UnitPriceExclTax> 
     <LineTax>    5.9000000</LineTax> 
     <LinePriceExclTax>    42.1500000</LinePriceExclTax> 
     <ColorName /> 
     <UOM>Ea</UOM> 
     <Backorder>    1.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637548_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>941151</ItemID> 
     <ColorID /> 
     <Description>PENTEL Correction Tape 5mx5mm ZT35</Description> 
     <MainCategory>OFFICE SUNDRIES</MainCategory> 
     <SubCategory>Correction Fluid/Pens/Tape</SubCategory> 
     <LineNum>    4.0000000</LineNum> 
     <Qty>    2.0000000</Qty> 
     <UnitPriceExclTax>    25.1500000</UnitPriceExclTax> 
     <LineTax>    7.0400000</LineTax> 
     <LinePriceExclTax>    50.3000000</LinePriceExclTax> 
     <ColorName /> 
     <UOM>Ea</UOM> 
     <Backorder>    0.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637549_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>801215</ItemID> 
     <ColorID /> 
     <Description>MONDI ROTATRIM Copy Paper A4 80Gsm White</Description> 
     <MainCategory>A4 Paper</MainCategory> 
     <SubCategory>White Bond Paper</SubCategory> 
     <LineNum>    5.0000000</LineNum> 
     <Qty>    100.0000000</Qty> 
     <UnitPriceExclTax>    29.0100000</UnitPriceExclTax> 
     <LineTax>    406.1400000</LineTax> 
     <LinePriceExclTax>   2901.0000000</LinePriceExclTax> 
     <ColorName /> 
     <UOM>Pkt 500</UOM> 
     <Backorder>    0.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637552_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SALESID>   CAP716197SO</SALESID> 
     <INVOICEID>   CAP600795SI</INVOICEID> 
     <INVOICEDATE>2010/05/06</INVOICEDATE> 
     <NUMBERSEQUENCEGROUP /> 
     <LINENUM>    2.0000000</LINENUM> 
     <ITEMID>805236</ITEMID> 
     <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
     <NAME>Ruled Paper A4 Fnt/Marg JD76</NAME> 
     <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
     <INVENTTRANSID>  CAP5637543_060</INVENTTRANSID> 
     <QTYSALES>    4.0000000</QTYSALES> 
     <QTYORDERED>    4.0000000</QTYORDERED> 
     <QTYBACKORDERSALES>    4.0000000</QTYBACKORDERSALES> 
     <QTYBACKORDERINVENT>    4.0000000</QTYBACKORDERINVENT> 
     <SALESUNIT>EA</SALESUNIT> 
     <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
     <DATAAREAID>wal</DATAAREAID> 
     <RECID>622392608</RECID> 
     <RecVersion>1</RecVersion> 
    </Line> 
    <Line> 
     <SALESID>   CAP716197SO</SALESID> 
     <INVOICEID>   CAP600795SI</INVOICEID> 
     <INVOICEDATE>2010/05/06</INVOICEDATE> 
     <NUMBERSEQUENCEGROUP /> 
     <LINENUM>    3.0000000</LINENUM> 
     <ITEMID>941150</ITEMID> 
     <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
     <NAME>PENGUIN Correction Fluid 20ml White</NAME> 
     <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
     <INVENTTRANSID>  CAP5637546_060</INVENTTRANSID> 
     <QTYSALES>    6.0000000</QTYSALES> 
     <QTYORDERED>    6.0000000</QTYORDERED> 
     <QTYBACKORDERSALES>    6.0000000</QTYBACKORDERSALES> 
     <QTYBACKORDERINVENT>    6.0000000</QTYBACKORDERINVENT> 
     <SALESUNIT>EA</SALESUNIT> 
     <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
     <DATAAREAID>wal</DATAAREAID> 
     <RECID>622392609</RECID> 
     <RecVersion>1</RecVersion> 
    </Line> 
    <Line> 
     <SALESID>   CAP716197SO</SALESID> 
     <INVOICEID>   CAP600795SI</INVOICEID> 
     <INVOICEDATE>2010/05/06</INVOICEDATE> 
     <NUMBERSEQUENCEGROUP /> 
     <LINENUM>    5.0000000</LINENUM> 
     <ITEMID>867241</ITEMID> 
     <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
     <NAME>TRODAT PRINTY S/Inking Stamp Copy 4911</NAME> 
     <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
     <INVENTTRANSID>  CAP5637548_060</INVENTTRANSID> 
     <QTYSALES>    2.0000000</QTYSALES> 
     <QTYORDERED>    2.0000000</QTYORDERED> 
     <QTYBACKORDERSALES>    1.0000000</QTYBACKORDERSALES> 
     <QTYBACKORDERINVENT>    1.0000000</QTYBACKORDERINVENT> 
     <SALESUNIT>EA</SALESUNIT> 
     <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
     <DATAAREAID>wal</DATAAREAID> 
     <RECID>622392610</RECID> 
     <RecVersion>1</RecVersion> 
    </Line> 
</XML> 

您將看到XML是不相同的,但是標籤總是在同一個地方,而且現在1複製867241

我不希望爲了改變,只是刪除的元素。

希望的輸出是;

<XML> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>723073</ItemID> 
     <ColorID>02</ColorID> 
     <Description>Pentel LR7 Energel Metal Tip Refill 0.7mm</Description> 
     <MainCategory>WRITING INSTRUMENTS</MainCategory> 
     <SubCategory>Refill</SubCategory> 
     <LineNum>    1.0000000</LineNum> 
     <Qty>    6.0000000</Qty> 
     <UnitPriceExclTax>    10.0200000</UnitPriceExclTax> 
     <LineTax>    8.4200000</LineTax> 
     <LinePriceExclTax>    60.1200000</LinePriceExclTax> 
     <ColorName>Black</ColorName> 
     <UOM>EA</UOM> 
     <Backorder>    0.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637542_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>903420</ItemID> 
     <ColorID /> 
     <Description>STEPHENS JUNIOR Stapler Half Strip KW586</Description> 
     <MainCategory>OFFICE SUNDRIES</MainCategory> 
     <SubCategory>Staplers</SubCategory> 
     <LineNum>    2.0000000</LineNum> 
     <Qty>    3.0000000</Qty> 
     <UnitPriceExclTax>    32.2500000</UnitPriceExclTax> 
     <LineTax>    13.5400000</LineTax> 
     <LinePriceExclTax>    96.7500000</LinePriceExclTax> 
     <ColorName /> 
     <UOM>Ea</UOM> 
     <Backorder>    0.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637547_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>867241</ItemID> 
     <ColorID /> 
     <Description>TRODAT PRINTY S/Inking Stamp Copy 4911</Description> 
     <MainCategory>STAMPS DATERS NUMBERERS</MainCategory> 
     <SubCategory>Self Inking Stamps</SubCategory> 
     <LineNum>    3.0000000</LineNum> 
     <Qty>    1.0000000</Qty> 
     <UnitPriceExclTax>    42.1500000</UnitPriceExclTax> 
     <LineTax>    5.9000000</LineTax> 
     <LinePriceExclTax>    42.1500000</LinePriceExclTax> 
     <ColorName /> 
     <UOM>Ea</UOM> 
     <Backorder>    1.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637548_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>941151</ItemID> 
     <ColorID /> 
     <Description>PENTEL Correction Tape 5mx5mm ZT35</Description> 
     <MainCategory>OFFICE SUNDRIES</MainCategory> 
     <SubCategory>Correction Fluid/Pens/Tape</SubCategory> 
     <LineNum>    4.0000000</LineNum> 
     <Qty>    2.0000000</Qty> 
     <UnitPriceExclTax>    25.1500000</UnitPriceExclTax> 
     <LineTax>    7.0400000</LineTax> 
     <LinePriceExclTax>    50.3000000</LinePriceExclTax> 
     <ColorName /> 
     <UOM>Ea</UOM> 
     <Backorder>    0.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637549_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SupplierID>Waltons</SupplierID> 
     <InvoiceID>CAP600795SI</InvoiceID> 
     <InvoiceDate>20100506</InvoiceDate> 
     <ItemID>801215</ItemID> 
     <ColorID /> 
     <Description>MONDI ROTATRIM Copy Paper A4 80Gsm White</Description> 
     <MainCategory>A4 Paper</MainCategory> 
     <SubCategory>White Bond Paper</SubCategory> 
     <LineNum>    5.0000000</LineNum> 
     <Qty>    100.0000000</Qty> 
     <UnitPriceExclTax>    29.0100000</UnitPriceExclTax> 
     <LineTax>    406.1400000</LineTax> 
     <LinePriceExclTax>   2901.0000000</LinePriceExclTax> 
     <ColorName /> 
     <UOM>Pkt 500</UOM> 
     <Backorder>    0.0000000</Backorder> 
     <INVENTTRANSID>  CAP5637552_060</INVENTTRANSID> 
    </Line> 
    <Line> 
     <SALESID>   CAP716197SO</SALESID> 
     <INVOICEID>   CAP600795SI</INVOICEID> 
     <INVOICEDATE>2010/05/06</INVOICEDATE> 
     <NUMBERSEQUENCEGROUP /> 
     <LINENUM>    2.0000000</LINENUM> 
     <ITEMID>805236</ITEMID> 
     <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
     <NAME>Ruled Paper A4 Fnt/Marg JD76</NAME> 
     <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
     <INVENTTRANSID>  CAP5637543_060</INVENTTRANSID> 
     <QTYSALES>    4.0000000</QTYSALES> 
     <QTYORDERED>    4.0000000</QTYORDERED> 
     <QTYBACKORDERSALES>    4.0000000</QTYBACKORDERSALES> 
     <QTYBACKORDERINVENT>    4.0000000</QTYBACKORDERINVENT> 
     <SALESUNIT>EA</SALESUNIT> 
     <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
     <DATAAREAID>wal</DATAAREAID> 
     <RECID>622392608</RECID> 
     <RecVersion>1</RecVersion> 
    </Line> 
    <Line> 
     <SALESID>   CAP716197SO</SALESID> 
     <INVOICEID>   CAP600795SI</INVOICEID> 
     <INVOICEDATE>2010/05/06</INVOICEDATE> 
     <NUMBERSEQUENCEGROUP /> 
     <LINENUM>    3.0000000</LINENUM> 
     <ITEMID>941150</ITEMID> 
     <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
     <NAME>PENGUIN Correction Fluid 20ml White</NAME> 
     <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
     <INVENTTRANSID>  CAP5637546_060</INVENTTRANSID> 
     <QTYSALES>    6.0000000</QTYSALES> 
     <QTYORDERED>    6.0000000</QTYORDERED> 
     <QTYBACKORDERSALES>    6.0000000</QTYBACKORDERSALES> 
     <QTYBACKORDERINVENT>    6.0000000</QTYBACKORDERINVENT> 
     <SALESUNIT>EA</SALESUNIT> 
     <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
     <DATAAREAID>wal</DATAAREAID> 
     <RECID>622392609</RECID> 
     <RecVersion>1</RecVersion> 
    </Line> 
</XML> 

我可以使用XSLT 1或2

問候,

+0

可能重複[刪除xsl中的重複項](http://stackoverflow.com/questions/2344458/removing-duplicates-in-xsl) – Filburt

+0

是否有意在文檔的頂部和末尾拼寫元素「'/''? – hielsnoppe

回答

18

一XSLT 1.0解決方案:

下面是使用Muenchian解決方案分組

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:key name="kLineById" match="Line" use="ItemID|ITEMID"/> 

<xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match= 
    "Line[not(generate-id() = generate-id(key('kLineById', ItemID|ITEMID)[1]))]" 
    /> 
</xsl:stylesheet> 

請注意

  1. Muenchian grouping是XSLT 1.0中最高效的已知常規分組方法。

  2. "push" style使用。


II。 XSLT 2.0解決方案:

<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output omit-xml-declaration="yes" indent="yes"/> 

<xsl:template match="/*"> 
    <XML> 
     <xsl:for-each-group select="Line" group-by="ItemID | ITEMID"> 
     <xsl:sequence select="."/> 
     </xsl:for-each-group> 
    </XML> 
</xsl:template> 
</xsl:stylesheet> 

這兩種解決方案,當所提供的XML文檔應用:

<XML> 
     <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>723073</ItemID> 
      <ColorID>02</ColorID> 
      <Description>Pentel LR7 Energel Metal Tip Refill 0.7mm</Description> 
      <MainCategory>WRITING INSTRUMENTS</MainCategory> 
      <SubCategory>Refill</SubCategory> 
      <LineNum>    1.0000000</LineNum> 
      <Qty>    6.0000000</Qty> 
      <UnitPriceExclTax>    10.0200000</UnitPriceExclTax> 
      <LineTax>    8.4200000</LineTax> 
      <LinePriceExclTax>    60.1200000</LinePriceExclTax> 
      <ColorName>Black</ColorName> 
      <UOM>EA</UOM> 
      <Backorder>    0.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637542_060</INVENTTRANSID> 
     </Line> 
     <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>903420</ItemID> 
      <ColorID /> 
      <Description>STEPHENS JUNIOR Stapler Half Strip KW586</Description> 
      <MainCategory>OFFICE SUNDRIES</MainCategory> 
      <SubCategory>Staplers</SubCategory> 
      <LineNum>    2.0000000</LineNum> 
      <Qty>    3.0000000</Qty> 
      <UnitPriceExclTax>    32.2500000</UnitPriceExclTax> 
      <LineTax>    13.5400000</LineTax> 
      <LinePriceExclTax>    96.7500000</LinePriceExclTax> 
      <ColorName /> 
      <UOM>Ea</UOM> 
      <Backorder>    0.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637547_060</INVENTTRANSID> 
     </Line> 
     <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>867241</ItemID> 
      <ColorID /> 
      <Description>TRODAT PRINTY S/Inking Stamp Copy 4911</Description> 
      <MainCategory>STAMPS DATERS NUMBERERS</MainCategory> 
      <SubCategory>Self Inking Stamps</SubCategory> 
      <LineNum>    3.0000000</LineNum> 
      <Qty>    1.0000000</Qty> 
      <UnitPriceExclTax>    42.1500000</UnitPriceExclTax> 
      <LineTax>    5.9000000</LineTax> 
      <LinePriceExclTax>    42.1500000</LinePriceExclTax> 
      <ColorName /> 
      <UOM>Ea</UOM> 
      <Backorder>    1.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637548_060</INVENTTRANSID> 
     </Line> 
     <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>941151</ItemID> 
      <ColorID /> 
      <Description>PENTEL Correction Tape 5mx5mm ZT35</Description> 
      <MainCategory>OFFICE SUNDRIES</MainCategory> 
      <SubCategory>Correction Fluid/Pens/Tape</SubCategory> 
      <LineNum>    4.0000000</LineNum> 
      <Qty>    2.0000000</Qty> 
      <UnitPriceExclTax>    25.1500000</UnitPriceExclTax> 
      <LineTax>    7.0400000</LineTax> 
      <LinePriceExclTax>    50.3000000</LinePriceExclTax> 
      <ColorName /> 
      <UOM>Ea</UOM> 
      <Backorder>    0.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637549_060</INVENTTRANSID> 
     </Line> 
     <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>801215</ItemID> 
      <ColorID /> 
      <Description>MONDI ROTATRIM Copy Paper A4 80Gsm White</Description> 
      <MainCategory>A4 Paper</MainCategory> 
      <SubCategory>White Bond Paper</SubCategory> 
      <LineNum>    5.0000000</LineNum> 
      <Qty>    100.0000000</Qty> 
      <UnitPriceExclTax>    29.0100000</UnitPriceExclTax> 
      <LineTax>    406.1400000</LineTax> 
      <LinePriceExclTax>   2901.0000000</LinePriceExclTax> 
      <ColorName /> 
      <UOM>Pkt 500</UOM> 
      <Backorder>    0.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637552_060</INVENTTRANSID> 
     </Line> 
     <Line> 
      <SALESID>   CAP716197SO</SALESID> 
      <INVOICEID>   CAP600795SI</INVOICEID> 
      <INVOICEDATE>2010/05/06</INVOICEDATE> 
      <NUMBERSEQUENCEGROUP /> 
      <LINENUM>    2.0000000</LINENUM> 
      <ITEMID>805236</ITEMID> 
      <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
      <NAME>Ruled Paper A4 Fnt/Marg JD76</NAME> 
      <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
      <INVENTTRANSID>  CAP5637543_060</INVENTTRANSID> 
      <QTYSALES>    4.0000000</QTYSALES> 
      <QTYORDERED>    4.0000000</QTYORDERED> 
      <QTYBACKORDERSALES>    4.0000000</QTYBACKORDERSALES> 
      <QTYBACKORDERINVENT>    4.0000000</QTYBACKORDERINVENT> 
      <SALESUNIT>EA</SALESUNIT> 
      <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
      <DATAAREAID>wal</DATAAREAID> 
      <RECID>622392608</RECID> 
      <RecVersion>1</RecVersion> 
     </Line> 
     <Line> 
      <SALESID>   CAP716197SO</SALESID> 
      <INVOICEID>   CAP600795SI</INVOICEID> 
      <INVOICEDATE>2010/05/06</INVOICEDATE> 
      <NUMBERSEQUENCEGROUP /> 
      <LINENUM>    3.0000000</LINENUM> 
      <ITEMID>941150</ITEMID> 
      <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
      <NAME>PENGUIN Correction Fluid 20ml White</NAME> 
      <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
      <INVENTTRANSID>  CAP5637546_060</INVENTTRANSID> 
      <QTYSALES>    6.0000000</QTYSALES> 
      <QTYORDERED>    6.0000000</QTYORDERED> 
      <QTYBACKORDERSALES>    6.0000000</QTYBACKORDERSALES> 
      <QTYBACKORDERINVENT>    6.0000000</QTYBACKORDERINVENT> 
      <SALESUNIT>EA</SALESUNIT> 
      <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
      <DATAAREAID>wal</DATAAREAID> 
      <RECID>622392609</RECID> 
      <RecVersion>1</RecVersion> 
     </Line> 
     <Line> 
      <SALESID>   CAP716197SO</SALESID> 
      <INVOICEID>   CAP600795SI</INVOICEID> 
      <INVOICEDATE>2010/05/06</INVOICEDATE> 
      <NUMBERSEQUENCEGROUP /> 
      <LINENUM>    5.0000000</LINENUM> 
      <ITEMID>867241</ITEMID> 
      <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
      <NAME>TRODAT PRINTY S/Inking Stamp Copy 4911</NAME> 
      <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
      <INVENTTRANSID>  CAP5637548_060</INVENTTRANSID> 
      <QTYSALES>    2.0000000</QTYSALES> 
      <QTYORDERED>    2.0000000</QTYORDERED> 
      <QTYBACKORDERSALES>    1.0000000</QTYBACKORDERSALES> 
      <QTYBACKORDERINVENT>    1.0000000</QTYBACKORDERINVENT> 
      <SALESUNIT>EA</SALESUNIT> 
      <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
      <DATAAREAID>wal</DATAAREAID> 
      <RECID>622392610</RECID> 
      <RecVersion>1</RecVersion> 
     </Line> 
</XML> 

產生想要的,正確的結果:中

<XML> 
    <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>723073</ItemID> 
      <ColorID>02</ColorID> 
      <Description>Pentel LR7 Energel Metal Tip Refill 0.7mm</Description> 
      <MainCategory>WRITING INSTRUMENTS</MainCategory> 
      <SubCategory>Refill</SubCategory> 
      <LineNum>    1.0000000</LineNum> 
      <Qty>    6.0000000</Qty> 
      <UnitPriceExclTax>    10.0200000</UnitPriceExclTax> 
      <LineTax>    8.4200000</LineTax> 
      <LinePriceExclTax>    60.1200000</LinePriceExclTax> 
      <ColorName>Black</ColorName> 
      <UOM>EA</UOM> 
      <Backorder>    0.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637542_060</INVENTTRANSID> 
     </Line> 
    <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>903420</ItemID> 
      <ColorID/> 
      <Description>STEPHENS JUNIOR Stapler Half Strip KW586</Description> 
      <MainCategory>OFFICE SUNDRIES</MainCategory> 
      <SubCategory>Staplers</SubCategory> 
      <LineNum>    2.0000000</LineNum> 
      <Qty>    3.0000000</Qty> 
      <UnitPriceExclTax>    32.2500000</UnitPriceExclTax> 
      <LineTax>    13.5400000</LineTax> 
      <LinePriceExclTax>    96.7500000</LinePriceExclTax> 
      <ColorName/> 
      <UOM>Ea</UOM> 
      <Backorder>    0.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637547_060</INVENTTRANSID> 
     </Line> 
    <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>867241</ItemID> 
      <ColorID/> 
      <Description>TRODAT PRINTY S/Inking Stamp Copy 4911</Description> 
      <MainCategory>STAMPS DATERS NUMBERERS</MainCategory> 
      <SubCategory>Self Inking Stamps</SubCategory> 
      <LineNum>    3.0000000</LineNum> 
      <Qty>    1.0000000</Qty> 
      <UnitPriceExclTax>    42.1500000</UnitPriceExclTax> 
      <LineTax>    5.9000000</LineTax> 
      <LinePriceExclTax>    42.1500000</LinePriceExclTax> 
      <ColorName/> 
      <UOM>Ea</UOM> 
      <Backorder>    1.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637548_060</INVENTTRANSID> 
     </Line> 
    <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>941151</ItemID> 
      <ColorID/> 
      <Description>PENTEL Correction Tape 5mx5mm ZT35</Description> 
      <MainCategory>OFFICE SUNDRIES</MainCategory> 
      <SubCategory>Correction Fluid/Pens/Tape</SubCategory> 
      <LineNum>    4.0000000</LineNum> 
      <Qty>    2.0000000</Qty> 
      <UnitPriceExclTax>    25.1500000</UnitPriceExclTax> 
      <LineTax>    7.0400000</LineTax> 
      <LinePriceExclTax>    50.3000000</LinePriceExclTax> 
      <ColorName/> 
      <UOM>Ea</UOM> 
      <Backorder>    0.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637549_060</INVENTTRANSID> 
     </Line> 
    <Line> 
      <SupplierID>Waltons</SupplierID> 
      <InvoiceID>CAP600795SI</InvoiceID> 
      <InvoiceDate>20100506</InvoiceDate> 
      <ItemID>801215</ItemID> 
      <ColorID/> 
      <Description>MONDI ROTATRIM Copy Paper A4 80Gsm White</Description> 
      <MainCategory>A4 Paper</MainCategory> 
      <SubCategory>White Bond Paper</SubCategory> 
      <LineNum>    5.0000000</LineNum> 
      <Qty>    100.0000000</Qty> 
      <UnitPriceExclTax>    29.0100000</UnitPriceExclTax> 
      <LineTax>    406.1400000</LineTax> 
      <LinePriceExclTax>   2901.0000000</LinePriceExclTax> 
      <ColorName/> 
      <UOM>Pkt 500</UOM> 
      <Backorder>    0.0000000</Backorder> 
      <INVENTTRANSID>  CAP5637552_060</INVENTTRANSID> 
     </Line> 
    <Line> 
      <SALESID>   CAP716197SO</SALESID> 
      <INVOICEID>   CAP600795SI</INVOICEID> 
      <INVOICEDATE>2010/05/06</INVOICEDATE> 
      <NUMBERSEQUENCEGROUP/> 
      <LINENUM>    2.0000000</LINENUM> 
      <ITEMID>805236</ITEMID> 
      <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
      <NAME>Ruled Paper A4 Fnt/Marg JD76</NAME> 
      <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
      <INVENTTRANSID>  CAP5637543_060</INVENTTRANSID> 
      <QTYSALES>    4.0000000</QTYSALES> 
      <QTYORDERED>    4.0000000</QTYORDERED> 
      <QTYBACKORDERSALES>    4.0000000</QTYBACKORDERSALES> 
      <QTYBACKORDERINVENT>    4.0000000</QTYBACKORDERINVENT> 
      <SALESUNIT>EA</SALESUNIT> 
      <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
      <DATAAREAID>wal</DATAAREAID> 
      <RECID>622392608</RECID> 
      <RecVersion>1</RecVersion> 
     </Line> 
    <Line> 
      <SALESID>   CAP716197SO</SALESID> 
      <INVOICEID>   CAP600795SI</INVOICEID> 
      <INVOICEDATE>2010/05/06</INVOICEDATE> 
      <NUMBERSEQUENCEGROUP/> 
      <LINENUM>    3.0000000</LINENUM> 
      <ITEMID>941150</ITEMID> 
      <INVENTDIMID>  CAP0000594_061</INVENTDIMID> 
      <NAME>PENGUIN Correction Fluid 20ml White</NAME> 
      <CONFIRMEDDLV>2010/05/06</CONFIRMEDDLV> 
      <INVENTTRANSID>  CAP5637546_060</INVENTTRANSID> 
      <QTYSALES>    6.0000000</QTYSALES> 
      <QTYORDERED>    6.0000000</QTYORDERED> 
      <QTYBACKORDERSALES>    6.0000000</QTYBACKORDERSALES> 
      <QTYBACKORDERINVENT>    6.0000000</QTYBACKORDERINVENT> 
      <SALESUNIT>EA</SALESUNIT> 
      <ORIGSALESID>   CAP716197SO</ORIGSALESID> 
      <DATAAREAID>wal</DATAAREAID> 
      <RECID>622392609</RECID> 
      <RecVersion>1</RecVersion> 
     </Line> 
</XML> 
2

下列轉換爲我工作:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="Line"> 
     <xsl:copy-of select="." /> 
    </xsl:template> 
    <xsl:template match="/XML"> 
    <XML> 
    <xsl:apply-templates select="Line[not(
     ItemID=preceding-sibling::Line/ItemID or 
     ItemID=preceding-sibling::Line/ITEMID or 
     ITEMID=preceding-sibling::Line/ItemID or 
     ITEMID=preceding-sibling::Line/ITEMID)]" /> 
    </XML> 
</xsl:template> 
</xsl:transform> 

表達可以被簡化,如果ItemID/ITEMID被拼寫一致的所有大寫或駱駝案件。

+0

完美,感謝您的協助。 – M3mPh1z

+0

@ M3mPh1z:您可能還想考慮Dimitre Novatchev的解決方案。順便說一句:接受其中一個答案會給你和作者的聲望,併爲你賺取學者證書。親切的問候! – hielsnoppe