Project

Profile

Help

Performing HTTP POST from XSLT using either Java or .NET calls from Saxon

Added by Matt Klem about 1 month ago

Hi there. First time poster, but longtime user of XSLT under Saxon.

I was directed to try and ask about this request via my original post on Stack Overflow. You can find that post here: https://stackoverflow.com/questions/79148922/looking-to-perform-http-post-from-xslt-using-either-java-or-net-calls-from-saxo/79155315

I am trying to see if it is possible to perform an HTTP POST operation from an XSLT sheet, using the .NET extensions within Saxon. I cannot add any additional libraries (including the EXPath HTTP-client ones) to my environment because Saxon is rolled into a custom 3rd party application.

I am currently using Saxon EE v10.6 through a proprietary third party tool. The company I work for does not own this tool, but we use it daily as part of various services engagement with customers. This tool uses Saxon to perform XSLT transformations, primarily taking XML and converting it into Office Open XML to generate native MS Office documents.

Historically, when we've hit limits from this 3rd party app, we've written custom .NET DLLs that contain our own code, and invoked them from an XSLT stylesheet using the "clitype" qualifier on a namespace. This has worked extremely well and allowed us to extend functionality as needed.

However, we're now in a situation where the 3rd party use of Saxon is now executed within a cloud environment space. As a result, we can no longer add custom DLLs that our XSLT code can refer to. We can only use Saxon and any of the already-included libraries that come with it. We've tested the ability to invoke .NET from the cloud version with things like xmlns:test="clitype:System.Math" and test:Sqrt(64), etc so we know the cloud version still lets us call .NET. We just need to figure out how to do it for an HTTP POST.

Since I know we can refer to .NET namespaces/classes through clitype, I'm trying to see if there's anyway to replicate this type of .NET code through a stylesheet:

var url = "https://httpbin.org/post";
var client = new HttpClient;
var content = new StringContent(payload, System.Text.Encoding.UTF8,"application/json");
var response = await client.PostAsync(url, content);

And yes, I know this is a barebones example, but I just want to show something close to what I want to do. I've used a variation of that .NET code in Windows Workflow Foundation to successfull pass a JSON payload to an API endpoint (Power Automate specifically).

On the StackOverflow post, someone gave me a sheet with the logic worked out using Java but my third party tool rejects it with a weird meaningless error.

I was hoping someone here might have any suggestions on how to craft the XSLT to use .NET methods for invoking an HTTP post.

Any thoughts or suggestions are greatly appreciated. Thanks.

  • Matt

Please register to reply