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: http://github.com/petere/plxslt/
Here is roughly how this would look:
CREATE FUNCTION foo(xml) RETURNS xml AS $$
<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform">
$$ 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.