Actually, now that I look at it a bit more, your function doesn’t seem to provide the functionality it wants to.
If you make the outline, with the #contect (counter(heading).get().first()), then it gives the header counter of 0 in all of the outline. Do you know how to work around that?
Thanks!