XML::XSS::Element - XML::XSS element stylesheet rule
version 0.3.5
use XML::XSS; my $xss = XML::XSS->new; my $elt_style = $xss->element( 'foo' ); $elt_style->set_pre( ">>>" ); $elt_style->set_post( "<<<" ); print $xss->render( '<doc><foo>yadah yadah</foo></doc>' );
A XML::XSS rule that matches against the element nodes of the xml document to be rendered.
XML::XSS
For a given element 'foo', the displayed attributes follows the template:
pre <foo> intro content prechildren prechild [child node] postchild postchildren extro </foo> post
If it resolves to false, skip the element (and its children) altogether.
# don't show the tag if it doesn't have any child nodes $xss->set( foo => { process => sub { my ( $self, $node, $args ) = @_; return $node->childNodes->size > 0; } } );
As it's always the first attribute to be evaluated, it can also be used to set up the other rendering attributes.
$xss->set( '*' => { process => sub { my ( $self, $node, $args ) = @_; my $time = time(); $self->set( showtag => 1 ); $self->set( 'pre' => "\n>>> ". localtime . "\n" ); $self->set( 'post' => sub { "\n>>> took " . (time-$time) . "seconds\n"; } ); return 1; } } );
Attribute getter.
Attribute setter.
Printed before the element opening tag position.
If set to a true value, the open and closing tags of the xml element are printed out, if not, they are omited.
showtag defaults to true unless either the attribute pre or content is defined. This exception is to accomodate the common use of pre to replace the tags with something else, or when content is used to provide a templated replacement for the element.
showtag
pre
content
$css->set( 'subsection' => { pre => '<section level="2">', post => '</section>, } );
Accessor.
If defined, and if showtag is true, the element name will be replaced by this value in the opening and closing tags. If the opening tag has any attributes, they will be left untouched.
Printed after the element opening tag position.
If defined, it is used instead of the child nodes of the element, which are not processed (along with the prechildren and postchildren attributes).
prechildren
postchildren
Printed before the node's children, if there are any.
Printed before every child node.
Printed after every child node.
Printed after the node's children, if there are any.
Printed before the element closing tag position.
Printed after the element closing tag position.
Returns the parent XML::XSS stylesheet of this rule.
Shortcut for
$self->stylesheet->render( ... );
Yanick Champoux <yanick@cpan.org>
This software is copyright (c) 2017, 2013, 2011, 2010 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.
To install XML::XSS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::XSS
CPAN shell
perl -MCPAN -e shell install XML::XSS
For more information on module installation, please visit the detailed CPAN module installation guide.