Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Yanick (3196)

Yanick
  (email not shown publicly)
http://babyl.dyndns.org/techblog

Journal of Yanick (3196)

Saturday January 20, 2007
06:46 PM

XML::XPathScript 1.47 is out

[ #32217 ]

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;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.