I don't know what the best approach is.

You can call into ObjectScript from an XSLT using the isc:evaluate function. This is handled by the class in the XSLTCallbackHandlerClass property in HS.Util.XSLTTransformer. The HealthShare callback handler is HS.Util.XSLTHelper. You can extend this class to add functions to isc:evaluate and then point the transformer at your callback class. This is discussed in the documentation:

HealthShare 2022.2 > Using XML Tools > Performing XSLT Transformations > Specifying Parameters for Use by the Stylesheet > Adding and Using XSLT Extension Functions
https://docs.intersystems.com/hs20222/csp/docbook/DocBook.UI.Page.cls?KE...