...
# into 1. blah
sub section_title {
my ( $self, $node, $args ) = @_;
my $section_nbr = $self->stash->{section_nbr}++;
return $section_nbr . ". " . $node->findvalue( '@title' );
}
By default, the stash is cleared when rendering a document. To change
this behavior, see "use_clean_stash" in XML::XSS::Document.
stash()
The attribute getter.
clear_stash()
Clear the stash.
OVERLOADING
Concatenation (.)
The concatenation operator is overloaded to behave as an alias for
"get()".
my $chapter = $xss.'chapter'; # just like $xss->get('chapter')
$chapter->set_pre( '' );
$chapter->set_post( '
' );
Gets really powerful when used in concert with the overloading of the
rules and style attributes:
# equivalent as example above
$xss.'chapter'.'pre' *= '';
$xss.'chapter'.'post' *= '
';
METHODS
set( $element_1 => \%attrs, $element_2 => \%attrs_2, ... )
Sets attributes for a rendering node.
The $name can be an XML element name, or one of the special keywords
"#document", "#text", "#comment", "#pi" or "*" (for the *catch-all*
element), which will resolve to the corresponding rendering object.
$xss->set( 'foo' => { rename => 'bar' } );
# same as $xss->element('foo')->set( rename => 'bar' );
$xss->set( '#text' => { filter => { uc shift } } );
# same as $xss->text->set( filter => { uc shift } );
Note that subsequent calls to "set()" are additive. I.e.:
$xss->set( foo => { pre => 'X' } );
$xss->set( foo => { post => 'Y' } ); # pre is still set to 'X'
If you want to delete an attribute, passes it "undef" as its value.
render( $xml, \%args )
Returns the output produced by the application of the stylesheet to the
xml document. The xml can be passed as a string, or as a "XML::LibXML"
object. Several "XML::LibXML" objects can also be passed, in which case
the return value will be the concatenation of their transformations.
my $sections = $xss->render( $doc->findnodes( 'section' ) );
The %args is optional, and will defaults to an empty hash if not
provided. The reference to %args is also passed to the recursive calls
to "render()" for the children of the processed node, which allows for
another way for parent/children nodes to pass information in addition to
the "stash".
# count the descendents of all nodes
$xss->set(
'*' => {
process => sub {
my ( $self, $node, $attrs ) = @_;
$attrs->{children}++;
return 1;
},
content => sub {
my ( $self, $node, $attrs ) = @_;
my %c_attrs;
my $c_ref = \%c_attrs;
my $output = $self->render( $node->childNodes, $c_ref );
$attrs->{children} += $c_ref->{children};
$self->{post} =
"\n>>> node has "
. ($c_ref->{children}||0)
. " descendents\n";
return $output;
},
} );
AUTHOR
Yanick Champoux
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.