.
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' *= '
';
=head1 METHODS
=head2 set( $element_1 => \%attrs, $element_2 => \%attrs_2, ... )
Sets attributes for a rendering node.
The C<$name> can be
an XML element name, or one of the special keywords C<#document>,
C<#text>, C<#comment>, C<#pi> or C<*> (for the
I 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 C 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 C as its
value.
=head2 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 C object.
Several C 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 C<%args> is optional, and will defaults to an empty
hash if not provided. The reference to C<%args> is also passed to
the recursive calls to C for the children of the processed
node, which allows for another way for parent/children nodes to pass
information in addition to the C.
# 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;
},
} );
=head1 AUTHOR
Yanick Champoux
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011 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.
=cut