« Bloody Blue Borders Main | More Charting Tips »

Removin` duplicates

I wrote about removing duplicate data a while back, I hit it as a problem again this week. Lets just say I was using an almost undocumented feature of the data extraction engine that gave me some unexpected results. Thats all Im saying cos Im not supposed to be using it.

I ended up with a bunch of duplicated rows which was anoying but because I was not supposed to be using it I could not moan or bug the dev boys and gals. So I needed a work around, thankfully the RTF template came to the rescue.
I combined a BIP function, xdoxslt:distinct_values and XSLs fabulous concept of a variable to get rid of my duplicate rows.

As I have mentioned before variables in XSL are strange things, they are not updatable which is a drag for most of us but they can hold complete chunks of the data tree which is a big plus for many of us.

All I had in my template was:

<?variable:metrics;xdosxlt:distinct_values(G_METRICS)?>

you could also go with this neat XPATH solution which checks an entry's siblings for duplicates.

<?variable:metrics;/APCARS/LIST_G_METRICS/G_METRICS[not(HOUR=preceding-sibling::G_METRICS/HOUR)]>>

We now have a variable that has the data we need. Now all we do is loop over it just like a regular repeating node

<?for-each:$metrics?> ... <? end for-each?>

Ideally I`d have that bug fixed so we get the right data set presented to the template but its not a bug cos Im not meant to be using that feature right :0)

Post a comment