From: Liam R E Quin [mailto:liam(_at_)w3(_dot_)org]
Sent: Tuesday, January 05, 2010 02:51 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Retrieving sequence of unique strings from another
sequence
On Tue, 2010-01-05 at 13:41 -0500, Houghton,Andrew wrote:
I have a sequence of strings, e.g., ('abc', 'def', 'def', 'ghi'), and
I want to create a new sequence that will have only the unique
strings in it.
[...]
Can anyone suggest how I might use one or more XSL 2.0 functions to
return only the unique strings.
$sequence[count(index-of($sequence, .)) eq 1]
maybe?
I think this is similar to what G. Ken Holman proposed:
for $each in $list
return if( count($list[.=$each])=1 ) then $each else ()
But both would probably preform slowly on large sequences.
Michael Kay suggested:
<xsl:for-each-group select="$list" group-by=".">
<xsl:sequence select="current-group()[last()=1]"/>
</xsl:for-each-group>
which probably would preform better on large sequences however,
I needed to produce the result sequence as part of a complicated
XPath expression. So I think the solution I'm leaning on is to
create an XSL 2.0 function:
<xsl:function name="my:unique-values" as="xsd:string*">
<xsl:param name="values" as="xsd:string*" />
<xsl:for-each-group select="$values" group-by=".">
<xsl:sequence select="current-group()[last() = 1]" />
</xsl:for-each-group>
</xsl:function>
Thank you all for the suggestions, Andy.
--~------------------------------------------------------------------
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>
--~--