NAME
XML::XSS::Element - XML::XSS element stylesheet rule
VERSION
version 0.1_0
SYNOPSIS
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>' );
DESCRIPTION
A XML::XSS
rule that matches against the element nodes of the xml document to be rendered.
RENDERING ATTRIBUTES
For a given element 'foo', the displayed attributes follows the template:
pre
<foo>
intro
content
prechildren
prechild
[child node]
postchild
postchildren
extro
</foo>
post
process
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;
}
} );
get_process()
Attribute getter.
set_process( $process )
Attribute setter.
pre
Printed before the element opening tag position.
showtag
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.
$css->set( 'subsection' => {
pre => '<section level="2">',
post => '</section>,
} );
showtag
Accessor.
set_showtag( $boolean )
rename
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.
intro
Printed after the element opening tag position.
content
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
Printed before the node's children, if there are any.
prechild
Printed before every child node.
postchild
Printed after every child node.
postchildren
Printed after the node's children, if there are any.
extro
Printed before the element closing tag position.
post
Printed after the element closing tag position.
METHODS
stylesheet()
Returns the parent XML::XSS
stylesheet of this rule.
render( .. )
Shortcut for
$self->stylesheet->render( ... );