AxKit2
view release on metacpan or search on metacpan
lib/AxKit2/Transformer/XPathScript.pm view on Meta::CPAN
my $xps = XML::XPathScript->new( stylesheetfile => $self->{stylesheet} );
my $parser = XML::LibXML->new;
my $result = $xps->transform( $dom );
my $out_dom;
unless ( eval { $out_dom = $parser->parse_string( $result ) } ) {
$out_dom = $parser->parse_string(
'<xpathscript:wrapper '
.'xmlns:xpathscript="http://babyl.dyndns.org/xpathscript" '
.'xpathscript:type="cdata">'
.'<![CDATA['
. $result
. ']]></xpathscript:wrapper>' );
}
return $out_dom, sub { $self->output(@_) };
}
sub output {
my ($self, $client, $dom) = @_;
$self->log( LOGDEBUG, 'in output' );
my $out;
my $ct = 'text/xml';
if ( my( $root ) = eval { $dom->findnodes( '/xpathscript:wrapper' ) } ) {
warn "xpathscript:wrapper";
$ct = $root->getAttribute( 'type' )
if $root->getAttribute( 'type' );
if ( $ct eq 'cdata' ) {
$ct = 'text/plain';
$out = $root->textContent;
}
else {
$out .= $_->toString for $root->childNodes;
}
}
else {
warn "pure XML, baby";
$out = $dom->toStringHTML;
( run in 0.351 second using v1.01-cache-2.11-cpan-454fe037f31 )