[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Retrieving sequence of unique strings from another

Subject: RE: Retrieving sequence of unique strings from another sequence
From: "Houghton,Andrew" <houghtoa@xxxxxxxx>
Date: Tue, 5 Jan 2010 16:49:50 -0500
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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.