Re: [xsl] finding out distinct node/values

Subject: Re: [xsl] finding out distinct node/values
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Wed, 10 Feb 2010 17:34:33 +0000
> And, please, hit me over the head: where is the second (hidden?) loop
> that would make this O(n^2)?


>> >    <xsl:for-each select="/table/rows/row/name">
>> >      <xsl:if test="not(. = preceding::name)">

If that is

test=". = key(....)[1]"

then for every n you are doing 1 comparison.

If you use the preceding axis:

test="not(. = preceding::name)"

then for every n, you are doing n comparisons (well n - 1) so thats
where the n^2 comes from.

I guess it might be more apparent if written like this:

<xsl:for-each select="/table/rows/row/name">
  <xsl:for-each select="preceding::name">
    <!-- do comparison -->

Andrew Welch

Current Thread