XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Add Condition check in a multi... (3)
-> - Eliminating Duplicates with XS... (3)
-> ->Eliminating Duplicates wi...
-> ->Eliminating Duplicates wi...
-> + Empty tags in XML (2)
-> + XML to XML transformations (5)
-> + XSLT problem (3)
-> + XSLT and Array (6)
-> + Problem with transforming XMLs... (3)
-> + Logging in XSLT? (3)
-> + svg can not view with msxml pr... (3)
-> + Newbie Sorting Question (5)
-> + xslt - get values from fist no... (5)
-> + RenderX logo at the buttom of ... (2)
-> + consolidate same nodes into on... (4)
-> + HOW DO I GET THE XSLT MAPPER? (2)
-> + Newbie - dublicating attribute... (2)
-> + Correct use of sum() (3)
-> + Using the sum() function (4)
-> + Prublem in XSLT (6)
-> + Newbie XPath Question (10)
-> + Reference to variable or param... (3)
-- Previous [1381-1400] [1401-1420] [1421-1440] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
XSLT n00bSubject: Eliminating Duplicates with XSLT
Author: XSLT n00b
Date: 16 Aug 2006 09:35 AM
I am new to XSLT and have a particular problem that I hope there is a simple solution for. I would like to eliminate all duplicates when the XSLT transforms my XML. For instance, I only want a unique value to be displayed once. My data looks like this:

<all>
<desc>
<one>Instruments</one>
<two>Volumetric Glassware</two>
<three>Flask1</three>
</desc>
<desc>
<one>Instruments</one>
<two>Volumetric Glassware</two>
<three>Flask2</three>
</desc>
</all>


Snippet of my XSLT:
<xsl:for-each select="all/desc">
<xsl:value-of select="one"/><br />
<xsl:value-of select="two"/><br />
<xsl:value-of select="three"/><br />
</xsl:for-each>

The data currently comes out as:

Instruments
Volumetric Glassware
Flask1
Instruments
Volumetric Glassware
Flask2

How do I write the XSLT so that the data reads:

Instruments
Volumetric Glassware
Flask1
Flask2

Thanks

Postnext
XSLT n00bSubject: Eliminating Duplicates with XSLT
Author: XSLT n00b
Date: 16 Aug 2006 01:04 PM
Originally Posted: 16 Aug 2006 12:58 PM
I've made a little bit of progress but still having problems. Using the following xsl, I get it to sort out the duplicates, however, they are not ordered how I would like:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "html" />
<xsl:key name="levelone" match="//desc/one" use="."/>
<xsl:key name="leveltwo" match="//desc/two" use="."/>
<xsl:template match="/">
<xsl:for-each select="//desc/one[count(. | key('levelone', .)[1])= 1]">
<xsl:value-of select="." /><br />
<xsl:for-each select="//desc/two[count(. | key('leveltwo', .)[1])= 1]">
<xsl:value-of select="." /><br />
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

What happens is, it prints the first item in the <one> data, then prints all the <two> data underneath, then the next <one> data, then it duplicates all the <two> data again. I'm stumped. This data:

<all>
<desc>
<one>Instruments</one>
<two>Volumetric Glassware</two>
<three>Flask1</three>
</desc>
<desc>
<one>Instruments2</one>
<two>Volumetric Glassware</two>
<three>Flask2</three>
</desc>
<desc>
<one>Instruments</one>
<two>Volumetric Glassware2</two>
<three>Flask1</three>
</desc>
<desc>
<one>Instruments3</one>
<two>Volumetric Glassware3</two>
<three>Flask2</three>
</desc>
<desc>
<one>Instruments</one>
<two>Volumetric Glassware2</two>
<three>Flask1</three>
</desc>
<desc>
<one>Instruments4</one>
<two>Volumetric Glassware3</two>
<three>Flask2</three>
</desc>
</all>

Ouputs this:

Instruments2
Volumetric Glassware
Volumetric Glassware2
Volumetric Glassware3
Instruments3
Volumetric Glassware
Volumetric Glassware2
Volumetric Glassware3
Instruments
Volumetric Glassware>
Volumetric Glassware2
Volumetric Glassware3
Instruments4
Volumetric Glassware
Volumetric Glassware2
Volumetric Glassware3

What I want is this:

Instruments
Volumetric Glassware
Volumetric Glassware2

Instruments2
Volumetric Glassware

Instruments3
Volumetric Glassware3

Instruments4
Volumetric Glassware3

Posttop
Tony LavinioSubject: Eliminating Duplicates with XSLT
Author: Tony Lavinio
Date: 17 Aug 2006 07:57 AM
Which version of Stylus Studio are you using, so we know
how best to answer your question?
(Remember you are using the Stylus Studio Developer Network, a
free resource to Stylus Studio users only.)

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.