Re: [xsl] Select unique xsl:key

Subject: Re: [xsl] Select unique xsl:key
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 24 Dec 2008 10:50:59 -0500
Hi,

At 01:45 AM 12/24/2008, you wrote:
How to avoid duplicate key value in XSLT, it should select only unique
values. Here I am moving affiliation to referenced authors. "AF3-7" coming
three times, it should select only one very first referenced.

I don't think this is a clear specification.


AF3-7 is referenced three times, but it appears only once in the source. Because it is retrieved by the key every time it is referenced, it appears in the result three times.

Maybe you want it to appear in the result only the first time it is referenced. But you haven't said this so I'm guessing; nor have you said what you want to happen after the first time. (Is it dropped? should a link to its appearance be made?)

In any case, you are already avoiding duplicate references -- even if more than one AF3-7 appears in the source, only the first will be used, due to the predicate filter on the expression 'key('kyaff',following-sibling::AFFILIATION.CLINK/@LINKENDS)[1]'.

If you want to avoid processing references after the first, one way to do this is to define a reverse key to the referencing elements (instead of to the elements referenced), as in:

<xsl:key name="aff-references" match="AFFILIATION.CLINK" use="@LINKENDS"/>

then use this to determine whether, when you process an AFFILIATION.CLINK element, it is the first such element that references its target.

But again, I'm just guessing. In any case, the solution is in specifying what you want. :-)

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread