In my case, I'm trying to update the DTOSteps (first child node) values of @CoverageCd == "TRIA".
But my dataweave code updates all the DTOSteps of @CoverageCd == "TRIA". Assume that the variable in this code returns some values.
My Dataweave code:
%dw 2.0
var multiChar = "X"
output application/xml
fun TRIAtransformSteps(x, index)=
x match {
case is Object -> x mapObject
if ($$ as String == "DTOSteps")
{
DTOSteps: TRIAtransformNewSteps()
}
else
(($$): TRIAtransformSteps($, index+1))
else -> $
}
fun TRIAtransformNewSteps()=
{
DTOStep @(Order:vars.Desc[0], Name:"Rate Area: "++ vars.Desc ++ " TRIA",Desc:vars.Desc ++ " TRIA Layer Premium", Operation:"+", Factor: vars.drcvalues.TRIACharge , Value:vars.drcvalues.TRIACharge ): null
}
fun TRIAtransformCoverage(x, index)=
x match {
case is Object -> x mapObject
if ($$ as String == "DTOCoverage" and $$.@CoverageCd == "TRIA")
{
DTOCoverage @(( $$.@ ) ): TRIAtransformSteps($, index)
}
else
(($$): TRIAtransformCoverage($, index+1))
else -> $
}
---
TRIAtransformCoverage(payload,1)
Input payload: https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/input_xml_request_TRIA.xml
Output in getting : https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/My_output.xml
Expected Output : https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/Expected_output.xml
How do I break the iteration when the First DTOSteps is selected?