I seem to have a constant problem with getting the correct results with grouping. I have a problem I could use help with that is either a sort or grouping problem. Possibly both.
I have to sets of elements, <figure> and <fnc>. They are currently listed in a order based on a specific attribute. I need to intersperse these element based on two different corresponding attribute with the same values (an ID, IDREF relationship).
Due to the nature of my company's content, I cannot post that, so what I am posting a dummy sample.
<fgc_list>
<fnc code="01" id="fgc1"/>
<fnc code="0101" id="fgc1.1" parent-id="fgc1"/>
<fnc code="02" id="fgc2"/>
<fnc code="0201" id="fgc2.1" parent-id="fgc2"/>
<fnc code="020101" id="fgc2.1.1" parent-id="fgc2.1"/>
<fnc code="020102" id="fgc2.1.2" parent-id="fgc2.1"/>
<figure figid="1" parent-id="fgc1.1"/>
<figure figid="2" parent-id="fgc1.1"/>
<figure figid="3" parent-id="fgc2.1"/>
<figure figid="4" parent-id="fgc2.1.2"/>
</fgc_list>
Desired Result:
<fgc_list>
<fnc code="01" id="fgc1"/>
<fnc code="0101" id="fgc1.1" parent-id="fgc1"/>
<figure figid="1" parent-id="fgc1.1"/>
<figure figid="2" parent-id="fgc1.1"/>
<fnc code="02" id="fgc2"/>
<fnc code="0201" id="fgc2.1" parent-id="fgc2"/>
<fnc code="020101" id="fgc2.1.1" parent-id="fgc2.1"/>
<figure figid="3" parent-id="fgc2.1"/>
<fnc code="020102" id="fgc2.1.2" parent-id="fgc2.1"/>
<figure figid="4" parent-id="fgc2.1.2"/>
</fgc_list>
I need the <fnc> element to remain in the current order, but insert the sibling <figure> elements with the attribute "parent-id" where that value matches the "id" attribute of the preceding <fnc>.
Charles
|