I don't understand some things in your macro.
Why are you using two different methods to create the links?
I am using something like the following snippet, but i use it with two "basic" macros. Maybe you can use the idea of snippet in your context.
\define basic-macro(z) x5 y3 $z$
\define complex-macro(x, y)
\whitespace trim
<$set name="result"
filter=" [<__y__>!match[]]"
value="""<$macrocall $name="basic-macro" z=<<__x__>> />"""
emptyValue="""<$macrocall $name="basic-macro" />""" >
<<result>>
</$set>
\end
Examples:
`<<complex-macro Z>>`=><<complex-macro Z>>
`<<complex-macro Z test>>`=><<complex-macro Z test>>
Maybe you don't need use macrocall widget and you can use basic macro call <<basic-macro $x$ $y$>> . It depends if you need call the parameters as variables or if it is enought the text sustitution of the parameter. Also in the filter you could use it the text sustitution, in the snippet [[$y$]!match[]]