Thanks to RobertLRobertL for this answeranswer.
I also came up with a combination of grep/awk/sed to achieve the same but it is slower obviously. Just wanted to put it out there.
egrep -w ""\<SOURCE"|"SOURCEFIELD.*XYZ.*"" sample.xml|grep -B1 XYZ|grep -w SOURCE|\
> awk -F" NAME =" '{print $2}'|awk '{print $1}'|sed 's/"//g'