Skip to content

Conversation

@jcflack
Copy link
Contributor

@jcflack jcflack commented Nov 21, 2020

My usual advice to anyone considering XSLT 1.0 is "run away!" because it is so primitive and limiting compared to the later versions. And certainly what's possible by downloading Saxon and using XSLT 3 or XQuery 3.1 is far and away preferable to struggling with XSLT 1.0.

Its one advantage is that it is directly included in Java with no need of a large, separately-downloaded jar, and that's enough to make it useful if there's some simple transformation to be done that doesn't require the big guns. Another redeeming feature of Java's XSLT support is that it can call out to Java methods, often allowing a way around the otherwise crippling limitations of strict XSLT 1.0.

So, it is worthwhile to take the existing example methods demonstrating the XSLT 1.0 support and give them a little further polishing to make them convenient for more serious use.

Although XSLT 1.0 is very much like punishment when a modern version
is available with Saxon, it does have the advantage of being included
in Java rather than a large separate download. Now that it's usable,
the example functions may as well be polished a bit (say, by making
the uninteresting-but-for-testing 'how' parameters optional, and
accepting an 'adjust' parameter) and made suitable for day-to-day use.

One useful feature of the XSLT 1.0 transformer is the ability to indent
XML: great for readability, not available in core PostgreSQL, and
easy to do here. It doesn't require any particular transformation
defined; the default identity transform from the no-argument
TransformerFactory.newTransformer is enough. So make it possible to pass
null for transformName for a plain identity transform, and add optional
indent and indentWidth direct arguments to make it simple.

This can also serve as an example to clarify just how one gets xalan
to indent, as the details are subtle enough to have needed hashing out
on Stack Overflow [1].

[1] https://stackoverflow.com/a/60610218/4062350
The ability in xalan to call out to Java methods can be extremely
useful in the otherwise very limited XSLT 1.0 dialect. But it sorely
needs an example, being fiddly enough to get right the first time
that newcomers might otherwise flee in frustration.
It's tedious to duplicate them in an @SQLAction GRANT or REVOKE.
Maybe that indicates it would be useful to add grant/revoke support
in annotations someday.
@jcflack jcflack merged commit a5fe818 into REL1_6_STABLE Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants