Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 2nd, 2008, 12:15 PM
Registered User
 
Join Date: Jan 2008
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old January 2nd, 2008, 12:25 PM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
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.

Reply With Quote
  #3 (permalink)  
Old January 2nd, 2008, 12:29 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.