XsltCompiledTransform does not allow embedded (inline script) code.
I came across this github project and need to test this out: brandonh-msft/EmbeddedXsltTestFunction: Demonstrates how to use custom code in an XML Transform from within an Azure Function (github.com)
On the face of it the embedded code can be migrated into ExtensionObjects – it sounds perfect!