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
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext 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.)

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
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.