xsl-list
[Top] [All Lists]

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

2012-10-09 03:47:31
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>