Re: [xsl] Lookup, eliminating duplicates and sorting

Subject: Re: [xsl] Lookup, eliminating duplicates and sorting
From: "Manfred Staudinger" <manfred.staudinger@xxxxxxxxx>
Date: Fri, 21 Jul 2006 16:06:01 -0700
On 20/07/06, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
Dimitre's solution is brilliant..

Here is a solution using the node-set extension function:
Sorry, I didn't state it explicitly, I need xslt 1.0 for browsers (no
but thanks anyway.

On 19/07/06, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> xslt 1.0 - I've a set of nodes, for which I want
> a. to replace some values (most will not change), then
> b. eliminate the duplicates and sort them.
> The text nodes represent URI's and are then used to
> create html links. So far I was only able to write in
> 2 different task what should be done in one:

One simple way to do this:

The following transformation:

<xsl:stylesheet version="1.0"

<xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:key name="kb" match="b[not(. = ../../e2/f/@c)]"  use="."/>
 <xsl:key name="kb" match="@b1" use="../../../e1/b[. = current()/../@c]"/>
  <xsl:key name="kDist" match="b | @b1" use="."/>

        <xsl:template match="/">
            <xsl:for-each select="key('kb', */e1/b)[generate-id() =
                                generate-id(key('kDist', .)[1])]">

        <b2><xsl:value-of select="."/></b2>

when applied on the provided source xml document:

                <f c="abe" b1="abc"/>
                <f c="abf" b1="abj"/>
                <f c="abg" b1="abi"/>
                <f c="abh" b1="abi"/>

produces the wanted result:

I'm still fascinated by Dimitre's solution. I also tried a first modification
(but without success): <e1> represents a response from a web service,
but <e2> is supplied by me and fairly static. So it would make sense to
put it in a separate document (teste2.xml), to enable the browser to cache it.
               <f c="abe" b1="abc"/>
               <f c="abf" b1="abj"/>
               <f c="abg" b1="abi"/>
               <f c="abh" b1="abi"/>
The first key definition
  <xsl:key name="kb" match="b[not(. = ../../e2/f/@c)]"  use="."/>
I assume should become
  <xsl:key name="kb" match="b[not(.
=document('teste2.xml')/e2/f/@c)]"  use="."/>
but I have no idea how to change the second
  <xsl:key name="kb" match="@b1" use="../../../e1/b[. = current()/../@c]"/>
How can I get a xpath expression for the (primary) source document if the
context is in another source document?
Regards, Manfred

Current Thread