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 $$
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform">
...
</xsl:stylesheet>
$$ 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.
1996 or 2006?
ReplyDelete:-)
ReplyDeleteThere seems to be a typo in the Makefile.am
ReplyDeleteIt 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.
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.
ReplyDelete