http://www.perlmonks.org?node_id=344368


in reply to Just use an XSLT stylesheet

...and it lacks the wealth of modules that CPAN offers.

Please note that XML::LibXSLT, the XSLT companion to XML::LibXML offers the "register_function" functionality which allows Perl functions to be called from stylesheets. An example (directly from the XML::LibXSLT documentation):

XML::LibXSLT->register_function("urn:foo", "bar", sub { scalar localt +ime });
and then later in a XSLT stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="urn:foo"> <xsl:template match="/"> The time is: <xsl:value-of select="foo:bar()"/> </xsl:template> </xsl:stylesheet>

This implies that CPAN modules can be made available at least in stylesheets using XML::LibXSLT.

I've used this approach for a client, who is now running about 40 syndicated websites out of a single database in production using this approach. Even the associated CMS is using XML::LibXSLT with special custom functions for handling forms and updating the underlying database.

Typical modules that I've made available that way (directly or indirectly) are DBI, LWP::UserAgent, POSIX, Digest::MD5, Email::Valid, Time::ParseDate, etc. etc. etc.

Liz

Replies are listed 'Best First'.
Re: Re: Just use an XSLT stylesheet
by mirod (Canon) on Apr 12, 2004 at 12:48 UTC

    But then, what is the upside of using this versus using perl + XML::LibXML for example?

    I understand that you simply offer custom functions, and that the users only have to know XSLT and those functions, not Perl in general, but is it really worth it? Is it so much easier to code XML processing in XSLT? Or is it a way to take the full power of Perl off the hands of inexperienced coders, using XSLT as a way to limit what they can do? That is a real question by the way, not a devious way to put down XSLT ;--)

      Or is it a way to take the full power of Perl off the hands of inexperienced coders, using XSLT as a way to limit what they can do?

      That's one way of putting it. This website started in 1995 originally, with a mixture of pregenerated pages from an Access database and pages that were kept up to date manually.

      The 1998 incarnation used Perl and MySQL, but did not have seperation of layout and content. Which meant, that as changes in layout were needed, I was needed to make changes to the underlying Perl code.

      The 2002 incarnation used the old database (which also generated XML) and XML::LibXSLT.

      The 2004 incarnation uses XML::LibXSLT and MySQL for everything. Now I don't have to worry about layout anymore. And the client can change layout whenever and however they feel like. Even for the CMS!

      I'm happy. The client is happy.

      I'm not saying it is the end to all means. But it was the right solution in this case. The other day they even added an RSS feed without me having to do anything!

      Liz