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

Subject: [xsl] Eliminating Duplicates - With sets of attributes defining uniqueness
From: "Thimmegowda, Balaji" <balaji_thimmegowda@xxxxxxxxx>
Date: Fri, 8 Jun 2007 11:22:17 -0400
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