26102

Removing duplicates in xsl

Question:

I have the following XML and I want to process it so that I do not get duplicates in the result set. I have simplified the problem to make it easier to understand. Also how can I use the results of one template as part of the input for another?

This:

<LINES xmlns:set="http://exslt.org/sets"> <STDINSTRSEQ>0</STDINSTRSEQ> <STDINSTRSEQ>1</STDINSTRSEQ> <STDINSTRSEQ>2</STDINSTRSEQ> </LINES>

is the desired result. <STDINSTRSEQ> is the name of the field that should be treated as the key. I have provided the sample data here.

<PURCHASEORDER> <POHEADER> <BODID>infor-nid:Elevon:SCMCS::12654_0198617S12 000 000:?&amp;verb=</BODID> <VERB></VERB> <TenantId>Elevon</TenantId> <ToLogicalId>lid://default</ToLogicalId> <FromLogicalId>lid://snipesm@mcsk12.net</FromLogicalId> <FromPartyId>snipesm@mcsk12.net</FromPartyId> <AccountingEntityId>SCMCS</AccountingEntityId> <ActionCode></ActionCode> <MessageId>lid://snipesm@mcsk12.net:1267198551845:4</MessageId> <UserId></UserId> <CurrentDateTime>2010-02-26T09:35:51Z</CurrentDateTime> <CTLENTYID>MCS</CTLENTYID> <VCKVAL>12654</VCKVAL> <POKVAL>0198617S12 000 000</POKVAL> <PCKVAL>000017</PCKVAL> <PODT>2005-03-16</PODT> <POREQDT>2005-06-30</POREQDT> <POQTEDT>2005-03-08</POQTEDT> <REQUISITIONNO>1103025T12 000 000</REQUISITIONNO> <REQHDATE></REQHDATE> <REQLDATE>2004-10-26</REQLDATE> <MTLREQDT></MTLREQDT> <RQSTRLONGNM></RQSTRLONGNM> <POCLASSOFORDCD>S</POCLASSOFORDCD> <SNGLDISTACKVAL></SNGLDISTACKVAL> <DISTACKVAL></DISTACKVAL> <CREATEDT>2005-03-16</CREATEDT> <POPROMDT></POPROMDT> <RORDDT></RORDDT> <RQSTRID>TEL</RQSTRID> <TAXCDREF></TAXCDREF> <DFLTDLVYLOCCD>407-P</DFLTDLVYLOCCD> <POGROSSAMT>1.00</POGROSSAMT> <SHIPPOINTNM></SHIPPOINTNM> <CRNCYCD>USD</CRNCYCD> <ORDVNDRCTACTID></ORDVNDRCTACTID> <LINEAMTTOT>0.00</LINEAMTTOT> <TERMSCD>18</TERMSCD> <FOBCD>01</FOBCD> <BYRCD>12</BYRCD> <INFORBUS>INFORBUS</INFORBUS> <VNDRLONGNM>DORI FOODS, INC.</VNDRLONGNM> <VNDRADDRLN001>P.O. BOX 11365</VNDRADDRLN001> <VNDRADDRLN002></VNDRADDRLN002> <VNDRADDRLN003></VNDRADDRLN003> <VNDRCITYLN>RICHMOND</VNDRCITYLN> <VNDRSTCD>VA</VNDRSTCD> <VNDRZIPCD>23</VNDRZIPCD> <VNDRZIPCDREST>2301365</VNDRZIPCDREST> <VCKTRDPRTNRID>12654</VCKTRDPRTNRID> <TPNAME>DORI FOODS, INC.</TPNAME> <TPADDR1>P.O. BOX 11365</TPADDR1> <TPADDR2></TPADDR2> <TPADDR3></TPADDR3> <TPCITY>RICHMOND</TPCITY> <TPZIP>232301365</TPZIP> <TPSTATE>VA</TPSTATE> <TPFAX>8043551631</TPFAX> <TPPARTNERID>12654</TPPARTNERID> <TPEMAIL>KITCHENJEREMYT@MCSK12.NET</TPEMAIL> <ECPOACKNHRSCNT>0</ECPOACKNHRSCNT> <ECSUPLMACKNHRSCNT>0</ECSUPLMACKNHRSCNT> <ECACKNPROCSTATCD>N</ECACKNPROCSTATCD> <UPLMACKNPROCSTATCD>N</UPLMACKNPROCSTATCD> <CORPTRDPRTNRID>MCSGENERIC</CORPTRDPRTNRID> <BYRSHRTNM>KEN RUBY</BYRSHRTNM> <BYRLONGNM>KEN RUBY</BYRLONGNM> <BYRUSERID>PURKENR</BYRUSERID> <BYRUSATELNBR></BYRUSATELNBR> <BYRTELNBR2VAL></BYRTELNBR2VAL> <BYRFAXXNBR></BYRFAXXNBR> <TERMSSHRTDESC>NET 30 DAY</TERMSSHRTDESC> <FRSTSTDINSTRCD>098</FRSTSTDINSTRCD> <XXC004>xxC004.STDINSTRDESC</XXC004> <INVCTONM></INVCTONM> <INVCTOADDRLN001></INVCTOADDRLN001> <INVCTOADDRLN002></INVCTOADDRLN002> <INVCTOADDRLN003></INVCTOADDRLN003> <INVCTOCITYLN></INVCTOCITYLN> <INVCTOSTCD></INVCTOSTCD> <INVCTOZIPCD></INVCTOZIPCD> <INVCTOCTRYCD></INVCTOCTRYCD> </POHEADER> <LINES> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>23</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>23.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>NOTE: THIS PURCHASE ORDER SERVES AS CONFIRMATION</STDINSTRDESC> <STDINSTRSEQ>0</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>AS PER BID OF MARCH 8, 2005.....</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>22</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>22.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>NOTE: THIS PURCHASE ORDER SERVES AS CONFIRMATION</STDINSTRDESC> <STDINSTRSEQ>0</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>PRICE: $47.89/CASE - SHIP LOT: 30 CASE</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>21</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>21.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>NOTE: THIS PURCHASE ORDER SERVES AS CONFIRMATION</STDINSTRDESC> <STDINSTRSEQ>0</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>BRAND: MCCORMICK 930839 - 25 LBS.</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>12</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>12.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>NOTE: THIS PURCHASE ORDER SERVES AS CONFIRMATION</STDINSTRDESC> <STDINSTRSEQ>0</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>PRICE: $78.92/CASE - SHIP LOT: 25 CASE</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>11</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>11.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>NOTE: THIS PURCHASE ORDER SERVES AS CONFIRMATION</STDINSTRDESC> <STDINSTRSEQ>0</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>BRAND: MCCORMICK 931025 - 25 LBS.</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>11</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>11.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>THAT WE ACCEPT THE TERMS AND CONDITIONS OUTLINED IN</STDINSTRDESC> <STDINSTRSEQ>1</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>BRAND: MCCORMICK 931025 - 25 LBS.</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>12</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>12.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>THAT WE ACCEPT THE TERMS AND CONDITIONS OUTLINED IN</STDINSTRDESC> <STDINSTRSEQ>1</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>PRICE: $78.92/CASE - SHIP LOT: 25 CASE</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>21</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>21.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>THAT WE ACCEPT THE TERMS AND CONDITIONS OUTLINED IN</STDINSTRDESC> <STDINSTRSEQ>1</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>BRAND: MCCORMICK 930839 - 25 LBS.</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>22</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>22.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>THAT WE ACCEPT THE TERMS AND CONDITIONS OUTLINED IN</STDINSTRDESC> <STDINSTRSEQ>1</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>PRICE: $47.89/CASE - SHIP LOT: 30 CASE</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>23</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>23.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>THAT WE ACCEPT THE TERMS AND CONDITIONS OUTLINED IN</STDINSTRDESC> <STDINSTRSEQ>1</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>AS PER BID OF MARCH 8, 2005.....</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>23</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>23.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>YOUR CONTRACT DATED 02/16/2007 FOR THE FOLLOWING</STDINSTRDESC> <STDINSTRSEQ>2</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>AS PER BID OF MARCH 8, 2005.....</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>22</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>22.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>YOUR CONTRACT DATED 02/16/2007 FOR THE FOLLOWING</STDINSTRDESC> <STDINSTRSEQ>2</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>PRICE: $47.89/CASE - SHIP LOT: 30 CASE</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>21</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>21.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>YOUR CONTRACT DATED 02/16/2007 FOR THE FOLLOWING</STDINSTRDESC> <STDINSTRSEQ>2</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>BRAND: MCCORMICK 930839 - 25 LBS.</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>12</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>12.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>YOUR CONTRACT DATED 02/16/2007 FOR THE FOLLOWING</STDINSTRDESC> <STDINSTRSEQ>2</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>PRICE: $78.92/CASE - SHIP LOT: 25 CASE</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> <LINE> <DLVYLOCCD></DLVYLOCCD> <STRGLOCID></STRGLOCID> <DLVYLOCCDLONGNM></DLVYLOCCDLONGNM> <DLVYLOCCDADDRLN001></DLVYLOCCDADDRLN001> <DLVYLOCCDADDRLN002></DLVYLOCCDADDRLN002> <DLVYLOCCDADDRLN003></DLVYLOCCDADDRLN003> <CITYLN></CITYLN> <STCD></STCD> <ZIPCD></ZIPCD> <CTRYCD></CTRYCD> <CTCTNM>KEN RUBY</CTCTNM> <POLINENBR>11</POLINENBR> <APPOLINECD>081</APPOLINECD> <UNIQID>11.081</UNIQID> <UOMCD></UOMCD> <STDINSTRDESC>YOUR CONTRACT DATED 02/16/2007 FOR THE FOLLOWING</STDINSTRDESC> <STDINSTRSEQ>2</STDINSTRSEQ> <MCKVAL></MCKVAL> <MTLDESC></MTLDESC> <POPROMDT></POPROMDT> <CRRNM></CRRNM> <MFGRREF></MFGRREF> <MFGRPARTREF></MFGRPARTREF> <PODTLDESC>BRAND: MCCORMICK 931025 - 25 LBS.</PODTLDESC> <XTRNVNDRUOMCD></XTRNVNDRUOMCD> <VNDRPARTREF></VNDRPARTREF> <VCVNDRPARTREF></VCVNDRPARTREF> <MTLLONGDESC></MTLLONGDESC> <XXR013>xxR013.MTLDESC</XXR013> <XXE4E00>xxE4E00.CMNTDESC</XXE4E00> <ORDQTY>0.0000</ORDQTY> <UOMSHRTDESC></UOMSHRTDESC> <UNITPRC>0.00000</UNITPRC> <VATTAXAMT>0.00</VATTAXAMT> <POLINEAMT>0.00</POLINEAMT> <XXE4F00>xxE4F00.UPLDFILENM</XXE4F00> </LINE> </LINES> </PURCHASEORDER>

Answer1:

If I understand correctly what you are asking for, then given your sample XML this would work

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates select="/PURCHASEORDER/LINES" /> </xsl:template> <xsl:template match="LINES"> <LINES xmlns:set="http://exslt.org/sets"> <xsl:apply-templates select="LINE/STDINSTRSEQ[not(. = preceding::STDINSTRSEQ)]"/> </LINES> </xsl:template> <xsl:template match="STDINSTRSEQ"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>

An optimized version that uses <a href="http://www.w3schools.com/xsl/el_key.asp" rel="nofollow"><xsl:key></a> to filter and provide unique results:

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:key name="STDIN" match="STDINSTRSEQ" use="./text()" /> <xsl:template match="/"> <xsl:apply-templates select="/PURCHASEORDER/LINES" /> </xsl:template> <xsl:template match="LINES"> <LINES xmlns:set="http://exslt.org/sets"> <xsl:apply-templates select="LINE/STDINSTRSEQ[generate-id(.) = generate-id(key('STDIN', .))]"/> </LINES> </xsl:template> <xsl:template match="STDINSTRSEQ"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>

Answer2:

I'm not sure about the apply-templates. I don't understand how they work. So for a XML that was like that:

<xml> <line>209</line> <line>209</line> <line>209</line> <line>100</line> <line>101</line> <line>101</line> <line>100</line> <line>102</line> <line>209</line> <line>101</line> <line>101</line> <line>101</line> <line>101</line> <line>209</line> <line>100</line> </xml>

to remove the repetitions, leaving only unique values:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="no" /> <xsl:template match="/"> <Output> <xsl:for-each select="//line"> <xsl:if test="not(. = preceding::line)"> <line> <xsl:value-of select="string(.)" disable-output-escaping="no" /> </line> </xsl:if> </xsl:for-each> </Output> </xsl:template> </xsl:stylesheet>

And the result was:

<Output> <line>100</line> <line>101</line> <line>102</line> <line>209</line> </Output>

And it was much quicker than the solution provided by Mads Hansen.

Answer3:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:key name="kSTDINSTRSEQ" match="STDINSTRSEQ" use="." /> <xsl:template match="PURCHASEORDER"> <xsl:apply-templates select="LINES" /> </xsl:template> <xsl:template match="LINES"> <LINES xmlns:set="http://exslt.org/sets"> <xsl:copy-of select=" LINE/STDINSTRSEQ[ generate-id() = generate-id(key('kSTDINSTRSEQ', .)[1]) ] " /> </LINES> </xsl:template> </xsl:stylesheet>

produces

<LINES xmlns:set="http://exslt.org/sets"> <STDINSTRSEQ>0</STDINSTRSEQ> <STDINSTRSEQ>1</STDINSTRSEQ> <STDINSTRSEQ>2</STDINSTRSEQ> </LINES>

To access this from another XSL template, write it to a temporary file and use the document() function. Alternatively, just do the grouping in the other XSLT file.

Recommend

  • How do I select distinct values from multiple mysql columns and put them in one PHP array?
  • Crystal Reports formula field: IF ISNULL(decimal) THEN 0.00 … does not work correctly
  • CONCAT ON Query in join more two table mysql table
  • Unable to delete HDFS Corrupt files
  • Prepopulate tabularinline with value from related lookup in manytomany field
  • Django Aggreagtion: Sum return value only?
  • Highlight cell when row is selected
  • jQuery window.scroll move div vertical in opposite direction
  • can I capture remotely executed commands with its output in the logfile in python?
  • Load PointerLockControl camera view to another camera
  • How to use predicate transpose in SWI-Prolog?
  • Removing Small Regions from a Binary Image
  • Set a Default value for each empty XML tags in XSLT 1.0
  • Why is 31 >= 20 returning False here when comparing day?
  • Currency Format with Knockout
  • Mysql grant all privileges is not getting applied
  • Postgresql huge performance difference when using IN vs NOT IN
  • Python how to format currency string
  • AutoMapper doesn't map calculated field to scalar
  • Display product cost in front end
  • how to return an object (from a MySQL temporary table) into a Coldfusion stored procedure?
  • PdfBox issue while changing page
  • Ruby spreadshet gem, how can I center align a number
  • Show indexes in MySQL table
  • SQL Server equivalent of Excel's TINV function
  • Error casting JSON to custom object
  • How to add totals to each group in SSRS
  • Why is indexPath for section 1 of a tableview starting with a value of [1,0]
  • mySQL INSERT IGNORE doesn't “ignore”
  • SSRS expression throws #Error - Possible reasons?
  • How is transparency actually implemented ?
  • R distribute weights over a vector
  • How can I handle Castor unmarshaling of SOAP messages when the namespace is defined inside the opera
  • roundoff double values in Java [duplicate]
  • GeoCoordinateWatcher is not getting GeoCoordinate Speed in emulator?
  • Excel VBA - add a custom number format
  • How to get desired format from ArrayList
  • two ways of displaying a decimal
  • Globalized custom number formatting - Variable decimal points
  • Why is it still possible to insert a foreign key that doesn't exist?