I have to transform xml file where i should check field id ‘0’, field id ‘1’ and sum field id ‘2’. For example I have:
<document>
<line id="0">
<field id="0">MAR</field>
<field id="1">doc1</field>
<field id="2">2</field>
</line>
<line id="1">
<field id="0">MAR</field>
<field id="1">doc2</field>
<field id="2">3</field>
</line>
<line id="2">
<field id="0">AAA></field>
<field id="1">doc4</field>
</line>
<line id="3">
<field id="0">MAR</field>
<field id="1">doc1</field>
<field id="2">4</field>
</line>
</document>
result should be:
<type-MAR>
<document>doc1</document>
<sum>6</sum>
</type-MAR>
<type-MAR>
<document>doc2</document>
<sum>3</sum>
</type-MAR>
there I should take all MAR lines, and show some results which are depends of field id ‘1’.
My idea was, first off all do cycle(for each) and use condition(when). Maybe somebody offer more omptimal decision.
I add new note, how to check if data comes like that:
<field id="0">MAR999</field>
<field id="1">doc1-1231</field>
First field i try to use function contains ‘MAR’, others substring-before ‘-‘. but I stuck when I try it use on Yours program. maybe you can take some advice for it?
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Explanation: The Muenchian method for grouping is used with the key defined as the concatenation of two elements.