Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT 1.0: Selecint unique nodes only

Reply
Thread Tools

XSLT 1.0: Selecint unique nodes only

 
 
Zachary Turner
Guest
Posts: n/a
 
      05-31-2007
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

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      05-31-2007
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/N...tml#d10012e339
http://www.dpawson.co.uk/xsl/sect2/N...tml#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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
finding nodes that don't match other nodes mlybarger@gmail.com XML 2 01-27-2005 07:26 PM
Looking A Nodes From Within Nodes Johnny Ooi XML 10 11-14-2004 06:55 PM
selecting nodes between other nodes Timo Nentwig XML 1 06-17-2004 04:54 AM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments