Japt, 15 15 12 bytes
kS q"|>" rÏiXJÉ - saved 3 by assuming no whitespaces as suggested by OP @79037662
kS - remove spaces q"|>" - split on pipe r - reduce by ÏiXJÉ - inserting before ) q"|>" - split on pipe r - reduce by ÏiXJÉ - inserting before )