[XSL-LIST Mailing List Archive Home]
[xsl] Ignoring Duplicates In key()
Subject: [xsl] Ignoring Duplicates In key()|
From: "Bob Portnell" <simply.bobp@xxxxxxxxx>
Date: Thu, 14 Sep 2006 10:17:01 -0700
Here's some fun in XSLT 1.0, using variously the MSXML 3.0 or xsltproc
processors (result behaviors are the same).
Here's some data...
<factor group="0" >
My need is to create a string of unique "components" in a "group". The
original XSLT for this relied on a recursion structure and wasn't
successfully blocking duplicates. My notion was to just wait for it to
finish all the recursion (for its other needs), and then hit it with a
key(), defined thus:
<xsl:key name="ComponentByGroup" match="component" use="../../@group" />
<xsl:if test="position() > 1">
<xsl:value-of select="." />
The desired output would be "gewgaw, widget", but for some reason I'm
getting only "widget." When applied to more complex data, in one case
where 12 items should be displayed, it's correctly stopping the
duplicates but also making two singletons vanish.
The [not(.=preceding::component)] is the basic structure I found for
reducing duplicates, but it doesn't seem to play quite nicely with the
key() ... it's reducing too many!