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

Re: New twist: eliminating nodes with duplicate content, cas

Subject: Re: New twist: eliminating nodes with duplicate content, case-insensi tive
From: Phil Lanch <phil@xxxxxxxxxxxxxxx>
Date: Mon, 06 Dec 1999 19:58:44 +0000
foo handle
Kay Michael wrote:
> 
> > My question is really how to eliminate duplicates, counting
> >    <handle>FOO</handle>
> > and
> >    <handle>foo</handle>
> > as duplicates.
> >
> > I still need an answer, if anyone knows one.
> >
> > <xsl:variable "unique-handles" select="//handle[not( self::node() =
> > following::handle )]"/>
> >
> 
> Can't be done in a single pass. (A brave assertion!) This is because there
> is no general existential quantifier in XSLT and no map() function to
> generate a set of strings by applying a function (translate()) to another
> set of strings. If you apply translate to a node-set, it only translates the
> string value of the first node.
> 
> Conceptually you need (using SQL-like syntax rather than pure predicate
> logic)
> 
> select="//handle[not exists( select N from following::handle where
> translate(N, $lc, $uc) =
> translate(self::node(), $lc, $uc)]

The code below does it in one pass (it was indeed a brave assertion!),
though not by getting a list of the unique nodes into a variable.

I don't think that list can be gotten into a top-level variable;
into a template-level variable would be possible after even messier use
of recusion than ...

<xsl:variable name="up" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lo" select="'abcdefghijklmnopqrstuvwxyz'"/>

<xsl:template match="//handle" name="handle">
  <xsl:param name="i" select="1"/>
  <xsl:choose>
    <xsl:when test="position() + $i &gt; last()">
      <handle><xsl:value-of select="translate(.,$up,$lo)"/></handle>
    </xsl:when>
    <xsl:when test="not( translate(.,$up,$lo) =
translate(following::handle[$i],$up,$lo) )">
      <xsl:call-template name="handle">
        <xsl:with-param name="i" select="$i + 1"/>
      </xsl:call-template>
    </xsl:when>
  </xsl:choose>
</xsl:template>

-- 

bahhumbug

phil

*witness relocation program alumnus*


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.