RE: RE: [xsl] Eliminating Duplicates - With sets of attributes defining uniqueness

Subject: RE: RE: [xsl] Eliminating Duplicates - With sets of attributes defining uniqueness
From: "Thimmegowda, Balaji" <balaji_thimmegowda@xxxxxxxxx>
Date: Mon, 11 Jun 2007 17:45:15 -0400
Thanks for the inputs, Michael.

I used the distinct function and was able to get it to work.

<xsl:for-each select="for $i in distinct-values(Chapter/concat(@Desc,
@sample, @ID)) return Chapter[$i=concat(@Desc, @sample, @ID)][1]">
	<xsl:if test="current()/@ID">
		<xsl:element name="TEST_ID">
			<xsl:value-of
select="concat(current()/@Desc,current()/@sample,current()/@ID)"/>
		</xsl:element>
	</xsl:if>
</xsl:for-each>




------------------------------

Date: Fri, 8 Jun 2007 16:38:17 +0100
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Subject: RE: [xsl] Eliminating Duplicates - With sets of attributes
defining uniqueness
Message-ID: <010001c7a9e3$0965b800$6401a8c0@turtle>

Which grouping technique are you using? XSLT 1.0 or 2.0?

Doing this using xsl:for-each-group or Muenchian grouping can be done
just
by concatenating the values. The only technique which doesn't extend to
this
case is the xx[not(.=preceding-sibling::xx)] approach.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Thimmegowda, Balaji [mailto:balaji_thimmegowda@xxxxxxxxx]
> Sent: 08 June 2007 16:22
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Eliminating Duplicates - With sets of
> attributes defining uniqueness
>
> Hi,
>
> Consider the following XML :
>
> <Book>
> 	<Chapter Desc="Desc1" sample="sample1" ID="ID1" name="chapter1"
> free="no"/>
> 	<Chapter Desc="Desc1" sample="sample1" ID="ID1" name="chapter2"
> free="no"/>
> 	<Chapter Desc="Desc2" sample="sample2" ID="ID1" name="chapter1"
> free="no"/>
> 	<Chapter Desc="Desc1" sample="sample1" ID="ID1" name="chapter1"
> free="no"/>
> 	<Chapter Desc="Desc1" sample="sample1" ID="ID1" name="chapter1"
> free="yes"/>
> </Book>
> <Book>
> 	<Chapter Desc="Desc1" sample="sample1" ID="ID1" name="chapter1"
> free="no"/>
> 	<Chapter Desc="Desc1" sample="sample1" ID="ID1" name="chapter1"
> free="no"/>
> 	<Chapter Desc="Desc2" sample="sample2" ID="ID1" name="chapter1"
> free="no"/>
> 	<Chapter Desc="Desc1" sample="sample1" ID="ID1" name="chapter1"
> free="no"/>
> 	<Chapter Desc="Desc1" sample="sample1" ID="ID2" name="chapter1"
> free="no"/>
> </Book>
>
> The attributes "ID", "name" and "free" are the ones that I
> need to check for uniqueness.
> The combination of each of this attribute with the attributes, "Desc"
> and "sample", makes it unique.
>
> For instance :
> When the attribute is "ID", a combination of "Desc","sample" and "ID"
> has to be unique within the current "Book" element.
> When the attribute is "name", a combination of
> "Desc","sample" and "name" has to be unique within the
> current "Book" element.
> When the attribute is "free", a combination of
> "Desc","sample" and "free" has to be unique within the
> current "Book" element.
>
> So, the output from the 1st Book element should be as follows :
>
> Output from 1st Chapter element
> <res>Desc1_sample1_ID1</res>
> <res>Desc1_sample1_chapter1</res>
> <res>Desc1_sample1_no</res>
>
> Output from the 2nd Chapter element
> <res>Desc1_sample1_chapter2</res>
>
> Output from the 3rd Chapter element
> <res>Desc2_sample2_ID1</res>
> <res>Desc2_sample2_chapter1</res>
> <res>Desc2_sample2_no</res>
>
> Output from the 4th Chapter element
> NONE - Since its a duplicate
>
> Output from the 5th Chapter element
> <res>Desc1_sample1_yes</res>
>
> The output from the 2nd Book element should be as follows :
>
> Output from the 1st Chapter element
> <res>Desc1_sample1_ID1</res>
> <res>Desc1_sample1_chapter1</res>
> <res>Desc1_sample1_no</res>
>
> Output from the 2nd Chapter element
> NONE - Since its a duplicate
>
> Output from the 3rd Chapter element
> <res>Desc2_sample2_ID1</res>
> <res>Desc2_sample2_chapter1</res>
> <res>Desc2_sample2_no</res>
>
> Output from the 4th Chapter element
> NONE - Since its a duplicate
>
> Output from the 5th Chapter element
> <res>Desc1_sample1_ID2</res>
>
> I have tried out a few stylesheets and I was able to
> eliminate the duplicates by considering all the attributes
> within the "Chapter"
> elements. But, I am not able to get it to work the way I have
> mentioned here.
>
> Any help is greatly appreciated.
>
> Thanks in advance,
> BT.


-----------------------------------------------------------------------------
-
Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD
and in Japan, as Banyu - direct contact information for affiliates is
available at http://www.merck.com/contact/contacts.html) that may be
confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and then
delete it from your system.

-----------------------------------------------------------------------------
-

Current Thread