[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: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 05 Jan 2010 14:24:37 -0500
Re:  Retrieving sequence of unique strings from another
At 2010-01-05 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. The XSL 2.0 function distinct-values is not what I want because:

<xsl:variable name="list" as="xsd:string*" select="('abc', 'def', 'def', 'ghi')" />
<xsl:variable name="uniq" as="xsd:string*" select="distinct-values($list)" />


will result in a sequence of ('abc', 'def', 'ghi') which is not what I'm looking for. What I am looking for is the sequence ('abc', 'ghi'). Unix people will recognize that distinct-values() returns the result of the uniq command without any options. While what I'm looking for is the result of the uniq command with the -u option.

Can anyone suggest how I might use one or more XSL 2.0 functions to return only the unique strings.

I hope the solution below helps.


. . . . . . . Ken

T:\ftemp>xslt2 andy.xsl andy.xsl
abc ghi
T:\ftemp>type andy.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                version="2.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:variable name="list" as="xsd:string*"
                select="('abc', 'def', 'def', 'ghi')"/>
  <xsl:variable name="uniq" as="xsd:string*"
                select="for $each in $list return
                        if( count($list[.=$each])=1 ) then $each else ()"/>
  <xsl:value-of select="$uniq"/>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>


-- UBL and Code List training: Copenhagen, Denmark 2010-02-08/10 XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19 XSLT/XQuery/XPath training: San Carlos, California 2010-04-26/30 Vote for your XML training: http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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.