While that works fine with Altova I don't get it to work with Saxon 9.8,
even with HE or with a stylesheet not using streamable merge sources,
Saxon indicates "XTDE3480: There is no current merge group".
Looking at the spec
https://www.w3.org/TR/xslt-30/#dt-current-merge-group it says "The
current merge group and current merge key are available within the
sequence constructor contained by an xsl:merge-action element." and "All
invocation constructs set the current merge group and current merge key
to absent" where the section
https://www.w3.org/TR/xslt-30/#dt-invocation-construct then details
"XPath function calls that bind to stylesheet functions" as one of the
invocation constructs so Saxon seems to be following the spec to reject
the use of current-merge-group() as the argument to my function.
I wonder why there is that restriction, at least when no streaming is
used I can't directly see a reason why a merge group can't be passed on
to a function.