Refactor output.xml flattening code.
Refactor output.xml flattening code.

Add higher level `if/else` to have separate code paths for start and
end events. Code gets simpler and due to conditions not being
evaluated unnecessarily there's a smallish performance boos as well.

Done after fixing #4254.

HelioGuilherme66/robotframework,HelioGuilherme66/robotframework,HelioGuilherme66/robotframework,robotframework/robotframework,robotframework/robotframework,robotframework/robotframework