Subject: [xsl] Removing duplicates where duplicates are determined by the concatenation of two elements From: <geirr.prestholdt@xxxxxxxxxxxxx> Date: Tue, 18 Dec 2007 15:02:43 +0100 |
Hi, consider the following problem: -i have this sorted list of names -I want to remove duplicates shown as the concatination of <surname> and <first_name> My question is: Can anyone tell me what is wrong with my XSLT(se below)? I hope you can help me. The subject of removing duplicates have been discussed before, but I have not found issues around the combination of duplicates and concatination. I am using XMLSpy 2007 rel3. GeirrP Sorted list: <?xml version="1.0" encoding="UTF-8"?> <persons> <person> <surname>Per</surname><first_name>Hansen</first_name> </person> <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>Jan</surname><first_name>Hansen</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> This is the result I want to achieve: <?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> Here is the XSLT: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/ | node() | @* | comment() | processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="/"> <xsl:variable name="persons"> <xsl:for-each select="//person"> <xsl:copy-of select="."/> </xsl:for-each> </xsl:variable> <tbody> <xsl:for-each select="$persons/person"> <xsl:variable name="pos" select="position( )"/> <xsl:if test="$pos = 1 or concat(./first_name,./surname) !=concat(./first_name[$pos - 1],./surname[$pos - 1])"> <xsl:copy-of select="."/> </xsl:if> </xsl:for-each> </tbody> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Testing for Last Group in, Michael Kay | Thread | Re: [xsl] Removing duplicates where, Martin Honnen |
Re: [xsl] ANN: 'Testing XSLT' train, Florent Georges | Date | Re: [xsl] Removing duplicates where, Martin Honnen |
Month |