[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Remove duplicates from a list

Subject: Re: Remove duplicates from a list
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Sun, 31 Oct 1999 22:02:15 +0000
perl remove duplicates
Given an input of:
<?xml version="1.0"?>
<data>
	<employee id="ttaylor">
		<skill title="java"/>
	</employee>

	<employee id="jdoe">
		<skill title="perl"/>
		<skill title="java"/>
	</employee>
</data>


and a stylesheet of:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
	<xsl:for-each select="//skill/@title[not( self::node() =
following::skill/@title )]">
		skill=<xsl:value-of select="." />		
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>		

you can get the output of:
G:\xmlSchema>xt t_.xml t_.xsl

                skill=perl
                skill=java

Tim Taylor wrote:
> 
> I have a similar, but more complicated problem.  Given the following XML
> snippet:
> 
>     <skill title="java"/>
>     <skill title="perl"/>
>     <skill title="java"/>
> 
> I would like to transform to:
> 
>     java
>     perl
> 

...

> Also, since this is really a learning excercise of my own creation, I'm
> really after comprehension more than the solution.  Please explain the
> solution, or provide pointers to information explaining it.  

I think I know why the expression 

	"//skill/@title[not(self::node() = following::skill/@title)]" 

works - because the XPATH spec states that 

	"If both objects to be compared are node-sets, then the comparison will
be true if and only if there is a node in the first node-set and a node
in the second node-set such that the result of performing the comparison
on the string-values of the two nodes is true" 

and each skill/@title is being compared to all skill/@title[s] following
it.

However if you replace the expression with 

	"//skill/@title[not( self::node()/text() =
following::skill/@title/text() )]"

it stops eliminating duplicates - this appears to be because in XPATH
(unlike DOM) atttribute nodes do not have text nodes (or any other
sub-nodes), they just have text values.

Francis.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.