Re: New twist: eliminating nodes with duplicate content, case-insensi tive

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
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