Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 2nd, 2008, 12:15 PM
Registered User
 
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Removing duplicate entries

Hi All,

I am a newbie to XSLT and I had a questions regarding removing duplicates in XML.

My XML looks something like this:

<item xsi:type="ns1:vendorProcess">
<waferProcessCode xsi:type="ns1:waferProcessCodeType">0.18C1P4M33.18 </waferProcessCode>
<waferSize xsi:type="xsd:integer">8</waferSize>
<fabCode xsi:type="ns1:fabCodeType">E_CHRT0608</fabCode>
<roadmapIndicator xsi:type="ns1:roadmapIndicatorType"/>
<riskStatus xsi:type="ns1:riskStatus">R</riskStatus>
</item>
<item xsi:type="ns1:vendorProcess">
<waferProcessCode xsi:type="ns1:waferProcessCodeType">0.18C1P4M33.18 </waferProcessCode>
<waferSize xsi:type="xsd:integer">8</waferSize>
<fabCode xsi:type="ns1:fabCodeType">E_MAGNC308</fabCode>
<roadmapIndicator xsi:type="ns1:roadmapIndicatorType"/>
<riskStatus xsi:type="ns1:riskStatus">R</riskStatus>
</item>

I am trying to pickout the waferProcessCode and assign it to a radio button. But Right now, my xslt code shows up duplicates i.e., for above example I get 2 radio buttons with the same value "0.18C1P4M33.18". I would want just one radio button to show up irrespective of how many ever similar values are there for a waferProcessCode.

Can someone pls help me how I need to go about doing that?? Any suggestions or sample code would be of gr8 help to put me in the right direction.

My xslt file is as follows:


<xsl:template match="/">
<xsl:apply-templates select="//waferProcessCode" />
</xsl:template>

<xsl:template match="waferProcessCode">
<br />
<input type="radio" name="results">
<xsl:attribute name="value">
<xsl:apply-templates />
</xsl:attribute>
</input>

<xsl:apply-templates />
</xsl:template>

</xsl:stylesheet>


Thanks,
Avantika
 
Old January 2nd, 2008, 12:25 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

There are different ways to get unique results, with XSLT 1.0 one way is to use e.g.
Code:
<xsl:template match="/">
<xsl:apply-templates select="//waferProcessCode[not(. = preceding-sibling::waferProcessCode)]" />
</xsl:template>
Another is to use Muenchian grouping and process only the first item in a group, see http://www.jenitennison.com/xslt/grouping/index.xml

With XSLT 2.0 you have can use xsl:for-each-group.

 
Old January 2nd, 2008, 12:29 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Removal of duplicates is often called "grouping", and you will find many references to grouping techniques if you search under this heading. XSLT 2.0 has a construct xsl:for-each-group designed to make this kind of problem easy to solve. In XSLT 1.0 it's harder, but there are techniques for doing it: see http://www.jenitennison.com/xslt/grouping.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate duplicate Entries using javascript sams ASP.NET 1.0 and 1.1 Professional 3 July 2nd, 2007 03:31 AM
How not to retrieve duplicate entries? EricTheViking Access ASP 2 January 12th, 2007 08:22 AM
Random Duplicate Entries SaraJaneQ Classic ASP Databases 6 July 16th, 2006 10:47 PM
How can I check for duplicate entries in XML gargkapil777 XSLT 2 December 22nd, 2005 01:00 PM
Delete duplicate entries from table expertcalling SQL Server 2000 2 January 2nd, 2005 11:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.