[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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

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
Keywords