[xsl] Filtering/Removing Truly Duplicate Elements

Subject: [xsl] Filtering/Removing Truly Duplicate Elements
From: "Wasiq Shaikh" <wasiq911@xxxxxxxxxxx>
Date: Wed, 18 Jul 2007 14:36:12 -0400
Hello everyone,

I have searched everywhere for a similar problem but most problems are actually very simple with simple solutions. But the techniques are the same. Except I cant seem to put differenct peices together. When i run my XSL, the desired result is not desired! :)

The Objective:
Remove truly duplicate elements, not just by name but by its attributes and attribute values.

The Example:
I have an xml input file (which is actually an XSD) with various <xsd:element>'s which may have many attributes.
The attributes I care about are "name" and "type". Below is a sample input file:

<xsd:element name="ABC" type="123" ... >
  <xsd:element name="def" type="456" .../>
  <xsd:element name="ghi" type="456" .../>

<xsd:element name="ABC" type="456" ...>
  <xsd:element name="ghi">
     <xsd:element name="def" type="456" .../>
     <xsd:element name="def"/>
  <xsd:element name="ABC"/>
  <xsd:element name="ABC"/>
  <xsd:element name="ghi" type="456" .../>

The desired result should be a flat list of elements:

  <element name="ABC"/>
  <element name="ABC" type="123"/>
  <element name="ABC" type="456"/>
  <element name="def"/>
  <element name="def" type="456"/>
  <element name="ghi"/>
  <element name="ghi" type="456"/>

The order of the result doesn't matter. But understand that all those elements are distinctly unique. I'm using Xalan Java 2.7/XPath 1.0.

My XSL Logic:
Since i need a flat list i will interate through "//xsd:element".
So, for every element encountered, check to see if there are any elements before it with the same name, and same type.

Sounds simple enough! But it isn't. I cant get the right combination of conditional logic with correct XPath syntax to execute this task. Maybe this task can not be done at all? I would like to know first if I'm wasting my time trying to figure this out or if there is any hope.

Please help as I'm sure this will benefit anyone else wanting to do the same task. Thank you!

Wasiq Shaikh

Windows Live Hotmail. Even hotter than before. Get a better look now. www.newhotmail.ca?icid=WLHMENCA148

Current Thread