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

Re: [xsl] removing duplicates from a sequence while retaining order


Subject: Re: [xsl] removing duplicates from a sequence while retaining order
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Tue, 9 Oct 2012 09:47:18 +0100

> If I'm not allowed to put the sequence into a variable, but I am allowed to
> duplicate the sequence in the expression:
>
> T:\ftemp>xslt2 david2.xsl david2.xsl
> <?xml version="1.0" encoding="UTF-8"?>Matthew Mark Luke John
> T:\ftemp>type david2.xsl
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   version="2.0">
>
> <xsl:template match="/">
>   <xsl:value-of
> select="('Matthew','Mark','Luke','Matthew','John')[position() =
> index-of(('Matthew','Mark','Luke','Matthew','John'),.)[1]]"/>
> </xsl:template>
>
> </xsl:stylesheet>
> T:\ftemp>
>
> I don't think I can do it otherwise, but I only have five minutes this
> evening to look at this.

I can't think of an xpath 2.0 without duplicating the sequence
either.. but with xpath 3.0 we can do:

fold-right(function($i, $j) {
           $i[not(index-of($j, $i))], $j },
           (), ('Matthew','Mark','Luke','Matthew','John') )



-- 
Andrew Welch
http://andrewjwelch.com


Current Thread
Keywords