P
peterwilson_69
How do I approach a complex grouping problem?
The basic idea is to remove duplicates, and move unique items and
configurations to the top of the document.
Example XML Source:
<xml>
<segment>
<laser wavelength=â€532†/>
<detector polarizer=â€true†/>
<data />
<data />
<data />
<data />
<data />
</segment>
<segment>
<laser wavelength=â€532†/>
<detector polarizer=â€false†/>
<data />
<data />
<data />
<data />
<data />
</segment>
<segment>
<laser wavelength=â€846†/>
<detector polarizer=â€true†/>
<data />
<data />
<data />
<data />
<data />
</segment>
</xml>
Desired Result, where <uniqueid> is an auto generated value to provide
temporary links between values.
1) Find unique values for Laser and Detector; easy to do.
2) Find unique combinations of Laser and Detector  this is where I’m
getting stuck!
3) Output segments (and data) using a link to the combination’s unique
ID.
<xml>
<laser id=â€<uniqueid>†wavelength=â€532†/>
<laser id=â€<uniqueid>†wavelength=â€846†/>
<detector id=â€<uniqueid>†polarizer=â€true†/>
<detector id=â€<uniqueid>†polarizer=â€false†/>
<combination id=â€<uniqueid>†laserid=â€<link-to-above>â€
detectorid=â€<link-to-above>†/>
<combination id=â€<uniqueid>†laserid=â€<link-to-above>â€
detectorid=â€<link-to-above>†/>
<combination id=â€<uniqueid>†laserid=â€<link-to-above>â€
detectorid=â€<link-to-above>†/>
<segment using-combination=â€<link-to-above-combination†/>
<data />
<data />
<data />
<data />
<data />
<segment using-combination=â€<link-to-above-combination†/>
<data />
<data />
<data />
<data />
<data />
<segment using-combination=â€<link-to-above-combination†/>
<data />
<data />
<data />
<data />
<data />
</xml>
I am part-way there, but am getting stuck. Any help would be
appreciated.
The basic idea is to remove duplicates, and move unique items and
configurations to the top of the document.
Example XML Source:
<xml>
<segment>
<laser wavelength=â€532†/>
<detector polarizer=â€true†/>
<data />
<data />
<data />
<data />
<data />
</segment>
<segment>
<laser wavelength=â€532†/>
<detector polarizer=â€false†/>
<data />
<data />
<data />
<data />
<data />
</segment>
<segment>
<laser wavelength=â€846†/>
<detector polarizer=â€true†/>
<data />
<data />
<data />
<data />
<data />
</segment>
</xml>
Desired Result, where <uniqueid> is an auto generated value to provide
temporary links between values.
1) Find unique values for Laser and Detector; easy to do.
2) Find unique combinations of Laser and Detector  this is where I’m
getting stuck!
3) Output segments (and data) using a link to the combination’s unique
ID.
<xml>
<laser id=â€<uniqueid>†wavelength=â€532†/>
<laser id=â€<uniqueid>†wavelength=â€846†/>
<detector id=â€<uniqueid>†polarizer=â€true†/>
<detector id=â€<uniqueid>†polarizer=â€false†/>
<combination id=â€<uniqueid>†laserid=â€<link-to-above>â€
detectorid=â€<link-to-above>†/>
<combination id=â€<uniqueid>†laserid=â€<link-to-above>â€
detectorid=â€<link-to-above>†/>
<combination id=â€<uniqueid>†laserid=â€<link-to-above>â€
detectorid=â€<link-to-above>†/>
<segment using-combination=â€<link-to-above-combination†/>
<data />
<data />
<data />
<data />
<data />
<segment using-combination=â€<link-to-above-combination†/>
<data />
<data />
<data />
<data />
<data />
<segment using-combination=â€<link-to-above-combination†/>
<data />
<data />
<data />
<data />
<data />
</xml>
I am part-way there, but am getting stuck. Any help would be
appreciated.