context always produces content, and you can’t extract anything from it. You have to but all code that depends on the contextual value inside the same context block. The below post explains context a bit.
In return, the context expression itself ends up opaque. We cannot directly access whatever results from it in our code, precisely because it is contextual […]
The other harder solution is to use state or metadata with label to save some data in the context scope and then retrieve it through state or query. But they also require context scope. And you need to place that (state/metadata) result in the document before trying to get the underlying data. And the new context must start after the placed-in-document data.