XML::XPathScript 1.47 is out

Yanick on 2007-01-20T23:46:12

It is with great relish that I announce that XML::XPathScript v1.47 is on its way to a CPAN mirror near you.

[ ED: Do'h! The test that was supposed to gracefully skip if B::XPath isn't installed bombs instead. (blame it on my naive assumption that 'eval { use B::XPath; 1 }' would work). I'll do a s/use/require/ on that test and release 1.48 tonight. ]

What is new in this release:

* template tag attributes can now be functions as well as strings.

For example,

$template->set( 'foo' => { testcode => sub { my( $n, $t ) = @_; my $name = $n->findvalue( 'name()' ); $t->set({ pre => transfurbicate( $name ) }); return $DO_SELF_AND_CHILDREN; } } );

can now be written

$template->set( 'foo' => { pre => sub { my( $n, $t ) = @_; my $name = $n->findvalue( 'name()' ); return transfurbicate( $name ); } } );

* The 'content' template attribute, which associates template elements to mini-stylesheets. E.g., the code

<% $template->set( 'foo' => { pre => '<newFoo foo_myattr="{@myattr}" >', post => '</newFoo>', action => 'bar', # only process 'bar' node children } ); %>

can now be written

<% $template->set( 'foo' => { content => <<'END_CONTENT' } ); <newFoo foo_myattr="{@myattr}" > <%# look Ma, we interpolate! %> <%~ bar %> <%# only process bar children %> </newFoo> END_CONTENT %> <%# process all foo's %> <%~ //foo %>

Or, to be more easy on the eye, we can use the short-hand version:

<%@ foo <newFoo foo_myattr="{@myattr}" > <%# look Ma, we interpolate! %> <%~ bar %> <%# only proces bar children %> </newFoo> %> <%# process all foo's %> <%~ //foo %>

* B::XPath now a supported DOM tree. Bored with transforming XML documents? How about transforming Perl Optrees? :-)

use B::XPath; use XML::XPathScript;

sub guinea_pig { my $x = shift; print "oink oink " x $x; }

my $xps = XML::XPathScript->new;

$xps->set_dom( B::XPath->fetch_root( \&guinea_pig ) ); $xps->set_stylesheet( '<%~ //print %>' );

print $xps->transform;