I am looking to transform source xml and combine couple of fields into single target string element in comma separated text.
Conditions Source Inputs (Engg1 to 5) are boolean type, only if value true it should be included in target list
E.g. XML
<Root-Element>
<EnggTypes>
<EnggFN>ABC<EnggFN>
<EnggLN>XYZ<EnggLN>
<EnggEML>[email protected]</EnggEML>
<Engg1>true</Engg1>
<Engg2>true</Engg2>
<Engg3>false</Engg3>
<Engg4>false</Engg4>
<Engg5>true</Engg5>
</EnggTypes>
</Root-Element>
Expected Transform
<Root-Element>
<EnggFN>ABC<EnggFN>
<EnggLN>XYZ<EnggLN>
<EnggEML>[email protected]</EnggEML>
<RoleTypes>Role1,Role2,Role5</RoleTypes>
</Root-Element>
Looking to achieve same in XQuery 1.0
I started overthinking and tried to use a local variable to see if I can do some if then else if to construct the string using previous value and concatenate but seems like that will not work as variable value cannot be changed once set!
{ if (Engg1/text()="true")
then (let $roleType:='Role1' return roleType)
else if (Engg2/text()="true")
then (let $roleType:=fn:concat($roleType,",","Role2") return roleType)
else if (Engg3/text()="true")
then (let $roleType:=fn:concat($roleType,",","Role3") return roleType)
else if (Engg4/text()="true")
then (let $roleType:=fn:concat($roleType,",","Role4") return roleType)
else if (Engg5/text()="true")
then (let $roleType:=fn:concat($roleType,",","Role5") return roleType)
else (fn:data($roleType))
}
Any inputs appreciated.
Thanks in advance