Re: [xsl] distinct values by xslt

Subject: Re: [xsl] distinct values by xslt
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 19 May 2011 12:12:15 -0400
JS,

On 5/19/2011 3:05 AM, JS Rawat wrote:
Hi Wendell,
I am using XSLT 2.0. will you please integrate it into below xslt!!!

I'm afraid I can't do that pro bono, at least not today.


Maybe someone else will pick it up. Even better, I am sure the effort required to learn how to apply the method yourself will be a very good investment.

Regards,
Wendell

As I understand it, this isn't really a "distinct values" problem, but
rather a problem of discriminating between nodes within sets of nodes, all
of which have the same values associated with them. The first question here
is whether this must be XSLT 1.0, or whether XSLT 2.0 can be used.

If you want to determine whether a node is the first node in the document
with a specific value associated with it (such as the first 'link' element
with a given @rid value), a good solution can be to use a
key:

<xsl:key name="link-by-rid" match="link" use="@rid"/>

Once this key is set up, you can examine any $link (where $link is a single
'link' element):

XSLT 1.0:

generate-id($link) = generate-id(key('link-by-rid',$link/@rid)[1])

XSLT 2.0:

$link is key('link-by-rid',$link/@rid)[1]

This method will also be faster, typically, than using the preceding:: axis.

You can do the same thing without a key, but that will often be slower too
(it depends on the processor):

XSLT 1.0:

generate-id($link) = generate-id((//link[@rid=$link/@rid])[1])

XSLT 2.0:

$link is (//link[@rid=$link/@rid])[1]

The extra parentheses are necessary here, unless you opt to use the
descendant:: axis instead of //.

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