xsl-list
[Top] [All Lists]

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

2007-06-11 14:46:09
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
From: "Michael Kay" <mike(_at_)saxonica(_dot_)com>
Subject: RE: [xsl] Eliminating Duplicates - With sets of attributes
defining uniqueness
Message-ID: <010001c7a9e3$0965b800$6401a8c0(_at_)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(_at_)merck(_dot_)com] 
Sent: 08 June 2007 16:22
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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.

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>