Sunday, August 30, 2009


Let me introduce the procedural language that you didn't yet know you needed: PL/XSLT.

PL/XSLT isn't actually that new. I faintly recall that I wrote it around the time of the Anniversary Summit in 2006, but never published it. Today I found the source code again, cleaned it up a bit, and put it up on GitHub:

Here is roughly how this would look:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xsl="">
$$ LANGUAGE xslt;

There are some conditions on the function definition:

  • The first parameter must be of type xml. It will receive the input document. Every function must have at least this one parameter.

  • The following function parameters will be supplied to the stylesheet as XSL parameters.

  • The return type must match the output method specified by the stylesheet. If it is xml, then the return type must be xml; if it is text or html, the return type must be text or varchar.

  • Triggers are not supported.

In the source code, I include an example function that converts the output of the table_to_xml etc. functions to HTML.

Of course, the question will arise whether this is sensible. I guess it is about as sensible as considering XSLT a programming language. Judge for yourself. :-)

In the words of GitHub: fork the project and add to it.


  1. There seems to be a typo in the
    It reads Libxslt_CLFAGS which presumably should be Libxslt_CFLAGS.

    You might consider making more clear what xslt processor the implementation is based on. That's what I was looking for when I saw the typo. (I didn't try to install, so I cannot say if it fails)

    I might have overlooked the obvious though.

  2. Peter - This is very nice. Thanks for sharing it. Readme and Install are quite well-written. Also, I didn't know it was this "easy" for users to "add" a language to a running PostgreSQL. Interesting.