Skip to Content
0
Jul 25, 2019 at 12:02 PM

Mapping Problem

109 Views Last edit Jul 25, 2019 at 12:04 PM 2 rev

experts - hello

Im tryin to solve this problem. Source message look like this:

<Root>
	<Name>Mike</Name>
	<Status>Active</Status>
	<Location>
		<Country>US</Country>
		<isLocal>no</isLocal>
		<isGlobal>no</isGlobal>
	</Location>
	<Location>
		<Country>UK</Country>
		<isLocal>no</isLocal>
		<isGlobal>yes</isGlobal>
	</Location>
</Root>

And then this is logic need to be followed

if (Status = "Active")
	if (count(location) > 1) //has more than 1<Location>
		if (isGlobal = "yes")
			isGlobal is "yes"
		else
			isGlobal is "no"
		
		if (isLocal = "yes")
			isLocal is "yes"
		else if (isLocal = "no" & count(/Root/Location[isLocal = 'yes']) = "0") //there is no <isLocal> = 'yes' in all <Location>
			isLocal is "yes"
		else 
			isLocal is "no"
	else //has only 1 <Location>
		if (isGlobal = "yes" & isLocal = "no")
			isGlobal is "yes"
			isLocal is "yes"
		else if (isGlobal = "yes" & isLocal = "yes")
			isGlobal is "yes"
			isLocal is "yes"
		else if (isGlobal = "no" & isLocal = "no")
			isGlobal is "no"
			isLocal is "no"
else
	isGlobal and isLocal are both ""

Based on logic, expected output is this:

<Root>
	<Name>Mike</Name>
	<Status>Active</Status>
	<Location>
		<Country>US</Country>
		<isLocal>yes</isLocal>
		<isGlobal>no</isGlobal>
	</Location>
	<Location>
		<Country>UK</Country>
		<isLocal>yes</isLocal>
		<isGlobal>yes</isGlobal>
	</Location>
</Root>

I tried graphical mapping but the ifS only returns 1 value. Can anyone give idea how to solve? And thank you in advance!!