Monday, March 31, 2008

HTTP extension for Saxon

I have just finished a little extension function for Saxon, to be able to send HTTP request from XSLT 2.0 (and get the result back). The idea is based on the SOAP extension from Andrew Welch, but is less restricted, as it can perform other HTTP requests (besides SOAP request over HTTP.)

The function take two parameters: a URI and an element that describe the request (the payload, the headers, the HTTP method, etc.) The later looks like:

<http-request method="post" mime-type="text/xml" charset="utf-8">
   <header name="Header-Name">...</header>
   <header name="Header2-Name">...</header>
      The textual value of body will be the payload of the HTTP request...

Let's say such an element is bound to the variable $request, then you can call ex:http-send($request, 'http://...'), and you will get a result that will look like:

<http-response code="200">
   <header name="Header-Name">...</header>
   <header name="Header-x-Name">...</header>
      The textual value of body was the payload of the HTTP response...

All the info, javadoc, JAR file, sample, can be found at This page contains a full sample sending a SOAP message to a Web service and formating the result to a simple text.

Labels: , ,


Anonymous Anonymous said...


I have downloaded your extension and am trying to use it with Saxon in Oxygen 10. I have tried to use the eXist sample XSLT and my own stylesheet, buy I always get the error given below. Do you think there might be something wrong with my setup? Any suggestions gratefully received:
Error in call to extension function {public static org.fgeorges.xslt.Exslt2.httpSend(net.sf.saxon.expr.XPathContext,,java.lang.String) throws net.sf.saxon.trans.XPathException}: Exception in extension function java.lang.IllegalStateException: There is another element?!? - There is another element?!?

Blogger Wabiloo said...

I have read your page on the XSLT http-send extension you have implemented with great interest. I have the need for this feature in my own work.
However, I am not able to use the Saxon processor (due to work constraints), and am using AltovaXML instead.

Do you think I’d be able to use your extension with AltovaXML, or is it too closely linked to the Saxon processor? If not, from what you know, do you think it could be easily migrated to work with AltovaXML?

Blogger Florent Georges said...

Hi Mark,

Sorry, I've just seen your comment, I don't know when you posted it. My first reflex anyway would be to have a look at the HTTP Client of EXPath instead. Please see


Florent Georges

Blogger Florent Georges said...

Hi Wabiloo,

If this is only to develop within XML Spy, I think you can use Saxon as an external processor, you don't have to use their built-in processor.

If you really use this processor in your project, outside of XML Spy, well, I would say "try to convince your project manager to switch to Saxon, or anything else but this one!" Every people I met who used this processor on real projects (hopefully a few) do have problems with it.

Regarding the question to adapt the extension to Altova's processor, honestly I do not know. That depends on the mechanisms they provide to write an extension function in another language, and on the amount of work required to write an HTTP client and deal with XML using that language.

And last but not least, if you find a way to use another processor, please have a look at the HTTP Client of EXPath <>. It replaces this old one which won't be supported anymore.

Kind regards, and thanks for your interest in this extension!

Florent Georges


Post a Comment

<< Home