Re: [xsl] Removing Duplicate Nodes

Subject: Re: [xsl] Removing Duplicate Nodes
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Mon, 7 Aug 2006 16:37:30 +0100
On 8/7/06, Ashutosh Bhardwaj <ashubhardwaj@xxxxxxxxxx> wrote:
In the xml given below I need to get first 8 unique values for first
element of docvector field , like (mutual fund, paul murray):
<?xml version="1.0" encoding="utf-8" ?>
<SEGMENTS>

- <SEGMENT NAME="webcluster">

- <RESULTPAGE>

- <RESULTSET FIRSTHIT="1" LASTHIT="25" HITS="25" TOTALHITS="4353"
MAXRANK="3019" TIME="0.2233">

- <HIT NO="1" RANK="2604" SITEID="0" MOREHITS="0">

<FIELD NAME="rank">2604</FIELD>

   <FIELD NAME="docvector">[mutual fund, 1][fund sponsored,
0.953463][practice guidelines, 0.852803]</FIELD>

</HIT>

- <HIT NO="2" RANK="2293" SITEID="0" MOREHITS="0">

  <FIELD NAME="rank">2293</FIELD>
  <FIELD NAME="docvector">[mutual fund, 1][mutual fund,
0.816497][positions library, 0.57735]</FIELD>

</HIT>

- <HIT NO="3" RANK="2292" SITEID="0" MOREHITS="0">

<FIELD NAME="rank">2292</FIELD>

  <FIELD NAME="docvector">[paul murray, 1][mutual fund, 0.786796][lauren
hanlon, 0.690066]</FIELD>

This is a classic example of why name-value pair style xml is bad - as soon as you need to add more information to the value field you have to come up with proprietary syntax to wedge it in... then you get problems down the line when your data contains your chosen delimiter.... Much better to create an element with attributes or child elements.

Anyway, if you are using XSLT 1.0 then you need use muechian grouping
with some string processing extensions or recursive templates.

If you are using XSLT 2.0 then your life is much easier and you can
tackle this a number of ways - distinct-values() or for-each-group etc
but the problem is a bit underspecified at the moment.....

Current Thread