AnsweredAssumed Answered

XML tag Multiple level looping

Question asked by rohit_tiwari on Oct 9, 2018
Latest reply on Oct 11, 2018 by rohit_tiwari

Hello friends,

 

I have requirement which i am not able to figure out the solution. I have a source xml like below, where group3 can repeat multiple times and  inside that <date.time.period> can repeat multiple times:

<GROUP3>
<details.of.transport>
<transport.stage.qualifier>10</transport.stage.qualifier>
<mode.of.transport>
<mode.of.transport.coded>23</mode.of.transport.coded>
</mode.of.transport>
<carrier>
<carrier.identification>HLCU</carrier.identification>
<code.list.qualifier>172</code.list.qualifier>
<code.list.responsible.agency.coded>182</code.list.responsible.agency.coded>
</carrier>
</details.of.transport>
<GROUP4>
<place.location.identification>
<place.location.qualifier>9</place.location.qualifier>
<location.identification>
<place.location.identification>ESVIT</place.location.identification>
<code.list.qualifier>139</code.list.qualifier>
<code.list.responsible.agency.coded>6</code.list.responsible.agency.coded>
<place.location>VITORIA</place.location>
</location.identification>
</place.location.identification>
<date.time.period>
<date.time.period.qualifier>133</date.time.period.qualifier>
<date.time.period>201803210000</date.time.period>
<date.time.period.format.qualifier>203</date.time.period.format.qualifier>
</date.time.period>
</GROUP4>
<GROUP4>
<place.location.identification>
<place.location.qualifier>11</place.location.qualifier>
<location.identification>
<place.location.identification>ESVLC</place.location.identification>
<code.list.qualifier>139</code.list.qualifier>
<code.list.responsible.agency.coded>6</code.list.responsible.agency.coded>
<place.location>VALENCIA</place.location>
</location.identification>
</place.location.identification>
<date.time.period>
<date.time.period.qualifier>132</date.time.period.qualifier>
<date.time.period>201803230000</date.time.period>
<date.time.period.format.qualifier>203</date.time.period.format.qualifier>
</date.time.period>
</GROUP4>
</GROUP3>
<GROUP3>
<details.of.transport>
<transport.stage.qualifier>20</transport.stage.qualifier>
<conveyance.reference.number>13W11</conveyance.reference.number>
<mode.of.transport>
<mode.of.transport.coded>1</mode.of.transport.coded>
</mode.of.transport>
<transport.means>
<type.of.means.of.transport.identification>13</type.of.means.of.transport.identification>
<type.of.means.of.transport>OCEAN VESSEL</type.of.means.of.transport>
</transport.means>
<carrier>
<carrier.identification>HLCU</carrier.identification>
<code.list.qualifier>172</code.list.qualifier>
<code.list.responsible.agency.coded>182</code.list.responsible.agency.coded>
</carrier>
<transport.identification>
<id.of.means.of.transport.identification>9143568</id.of.means.of.transport.identification>
<code.list.responsible.agency.coded>11</code.list.responsible.agency.coded>
<id.of.the.means.of.transport>LONDON EXPRESS</id.of.the.means.of.transport>
<nationality.of.means.of.transport.coded>BM</nationality.of.means.of.transport.coded>
</transport.identification>
</details.of.transport>
<GROUP4>
<place.location.identification>
<place.location.qualifier>9</place.location.qualifier>
<location.identification>
<place.location.identification>ESVLC</place.location.identification>
<code.list.qualifier>139</code.list.qualifier>
<code.list.responsible.agency.coded>6</code.list.responsible.agency.coded>
<place.location>VALENCIA</place.location>
</location.identification>
</place.location.identification>
<date.time.period>
<date.time.period.qualifier>180</date.time.period.qualifier>
<date.time.period>201804010106</date.time.period>
<date.time.period.format.qualifier>203</date.time.period.format.qualifier>
</date.time.period>
<date.time.period>
<date.time.period.qualifier>133</date.time.period.qualifier>
<date.time.period>201804021348</date.time.period>
<date.time.period.format.qualifier>203</date.time.period.format.qualifier>
</date.time.period>
</GROUP4>
<GROUP4>
<place.location.identification>
<place.location.qualifier>11</place.location.qualifier>
<location.identification>
<place.location.identification>COCTG</place.location.identification>
<code.list.qualifier>139</code.list.qualifier>
<code.list.responsible.agency.coded>6</code.list.responsible.agency.coded>
<place.location>CARTAGENA (COLOMBIA)</place.location>
</location.identification>
</place.location.identification>
<date.time.period>
<date.time.period.qualifier>132</date.time.period.qualifier>
<date.time.period>201804131642</date.time.period>
<date.time.period.format.qualifier>203</date.time.period.format.qualifier>
</date.time.period>
</GROUP4>
</GROUP3>

 

I need to map this to an another XML like below, <Elements> should repeat same no of times as group3 repeats:

 

<Elements>

<Element>

<Date1>

<Date2>

</Elements>

 

Date 1 should be mapped from <GROUP4>
<place.location.identification>
<place.location.qualifier> = "9"  and <GROUP4<date.time.period>
<date.time.period.qualifier> = "133"

 

I have used a simple javascript (if else )to check for 133 qual, but because <date.time.period> is repeating 2 times under group4 , I get an additional loop in target with <date1> value as null (when if condition doesn't satisfy output of script is null).

 

Tried with Properties but then i end up having same date value for all loops.

 

Any help here will be appreciated.

 

Thanks,

Rohit

Outcomes