[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Removing duplicates where duplicates are determine

Subject: Re: Removing duplicates where duplicates are determined by the concatenation of two elements
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 18 Dec 2007 14:21:45 GMT
Re:  Removing duplicates where duplicates are determine
I think you just want to use for-each-group

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  

<xsl:template match="persons">
<xsl:copy>
<xsl:for-each-group select="person" group-by="concat(surname,':',first_name)">
  <xsl:text>&#10;</xsl:text>
  <xsl:copy-of select="."/>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>


 saxon9 per.xml per.xsl
<?xml version="1.0" encoding="UTF-8"?><persons>
<person>
<surname>Per</surname><first_name>Hansen</first_name>
</person>
<person>
<surname>Per</surname><first_name>Olsen</first_name>
</person>
<person>
<surname>Jan</surname><first_name>Hansen</first_name>
</person>
<person>
<surname>Ole</surname><first_name>Pedersen</first_name>
</person>
<person>
<surname>jan</surname><first_name>Fredriksen</first_name>
</person>
<person>
<surname>Arne</surname><first_name>Jensen</first_name>
</person></persons>




If you are making variables you normally don't want to do 

   <xsl:variable name="persons">
                                               <xsl:for-each select="//person">
                                                               <xsl:copy-of select="."/>
                                               </xsl:for-each>
                               </xsl:variable>
which is very expensive (// causes a search of the entire document, and
<xsl:copy-of causes all  the elements to be copied
You could use
<xsl:variable name="persons" select="persons/person"/>
to seelct the original elements, not copies.

David

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.