XSLT 1.0: Selecint unique nodes only

Discussion in 'XML' started by Zachary Turner, May 31, 2007.

  1. I have a bunch of nodes like this:

    <a>
    <b>
    <b>
    <c>
    </a>

    <a>
    <b>
    <c>
    <d>
    <f>
    </a>

    I perform a select query similar to "a/*" (actually much more
    complicated, but the idea is the same), and set the result equal to a
    variable.

    <xsl:variable name="nodeSet" select="a/*"/>

    I now want a new variable like this:

    <xsl:variable name="uniqueNodeSet" select=""/>

    That only returns nodes in the set that do not have the same local-
    name() as any other element in the set. So basically just trim out
    elements with dupliacte local-names. I know this has come up before,
    I did search the usenet archives and there were many posts asking
    similar questions, but I was not able to massage the solutions into
    one that worked for my case. The best I could do was

    select="$nodeSet[not(local-name()=local-name(a/*))]"

    but for some reason that doesn't seem to get rid of the duplicates.
    I could probably do this using a long drawn out recursive template,
    but I'm sure there's an easier way.

    Any help greatly appreciated.

    Thanks
    Zachary Turner, May 31, 2007
    #1
    1. Advertising

  2. XSLT FAQ entries related to reducing a set to its unique members. Many
    of these approaches are related to sorting, but I think some of them are
    usable even if you don't sort.

    http://www.dpawson.co.uk/xsl/sect2/N6461.html#d10012e16
    http://www.dpawson.co.uk/xsl/sect2/N6461.html#d10012e339
    http://www.dpawson.co.uk/xsl/sect2/N6461.html#d10012e378
    http://www.dpawson.co.uk/xsl/sect2/N6280.html#d9903e16

    The Muenchian Method really is a nice little hack.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, May 31, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. johkar
    Replies:
    0
    Views:
    334
    johkar
    Feb 26, 2004
  2. Victor Engmark
    Replies:
    4
    Views:
    734
    Piet Blok
    Jun 1, 2004
  3. Rolf Kemper

    Use variables to get unique nodes

    Rolf Kemper, Oct 1, 2004, in forum: XML
    Replies:
    9
    Views:
    506
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=
    Oct 5, 2004
  4. ToshiBoy
    Replies:
    6
    Views:
    844
    ToshiBoy
    Aug 12, 2008
  5. Token Type
    Replies:
    9
    Views:
    354
    Chris Angelico
    Sep 9, 2012
Loading...

Share This Page