I'm trying to build a mapping logic for csv to xml conversion using xsl template. I am trying to map multiple values in each row to a group of repeatable elements in xml.
an example csv looks like this:
Field A Field B Field C Field D Field E Field F Field G Field H Field I FieldJ
123 bravo alpha 500 8.5 Portugal
123 charlie alpha 100 2.5
123 delta alpha 23 ECHO
When I do the conversion I would like to see it mapped as follows:
<Field_A>
<Field_B>
<Field_D>500</Field_D>
<Field_E>8.5</Field_E>
<Field_F>Portugal</Field_F>
</Field_B>
<Field_B>
<Field_G>100</Field_G>
<Field_H>2.5</Field_H>
<Field_B>
<Field_I>23</Field_I>
<Field_J>ECHO</Field_J>
</Field_B>
</Field_A>
So for each value in Field B, where value in Filed A & C are the same, map the values from Field D, E , F, G, H,I,J to specific elements.
To be honest, I don't know where to start. I have an if statement first:
<Field_A>
<xsl: if test="@Field_B = 'bravo'>
<Field_D><xsl: value - of select = "Field_D"/></Field D>
<Field_E><xsl: value - of select = "Field_E"/></Field_E>
.....
ETC.
How do I insert a for each loop and how can I make sure the right values are mapped to the right tags?
Do I need another column in csv with true/ false indicator which rows will have to belong to the same parent element and then map the value to a specific tag (for multiple Field_B elements that will be coming in csv from multiple rows but belonging to the same parent element)
When I do the conversion I would like to see it mapped as follows:
<Field_A>
<Field_B>
<Field_D>500</Field_D>
<Field_E>8.5</Field_E>
<Field_F>Portugal</Field_F>
</Field_B>
<Field_B>
<Field_G>100</Field_G>
<Field_H>2.5</Field_H>
<Field_B>
<Field_I>23</Field_I>
<Field_J>ECHO</Field_J>
</Field_B>
</Field_A>
There can also be multiple Field_B elements with differenc values.