[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Retrieving sequence of unique strings from another
> From: Liam R E Quin [mailto:liam@xxxxxx] > Sent: Tuesday, January 05, 2010 02:51 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: 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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|