package Pod::Manual::PodXML2Docbook; use strict; use warnings; use XML::XPathScript::Template; use XML::XPathScript::Processor; our $VERSION = '0.08_04'; our $processor; our $stylesheet = <<'END_STYLESHEET'; <% $XML::XPathScript::current->interpolating( 0 ); $Pod::Manual::PodXML2Docbook::processor = $processor; $template->import_template( $Pod::Manual::PodXML2Docbook::template ); %> <%~ / %> END_STYLESHEET our $template = XML::XPathScript::Template->new; $template->set( pod => { content => <<'END_CONTENT' } ); <%~ head %> <%~ sect1[title/text()="DESCRIPTION"] %> <%~ sect1[title/text()!="DESCRIPTION"] %> END_CONTENT $template->set( head => { showtag => 0, } ); $template->set( sect1 => { testcode => \&action_sect1 } ); $template->set( "sect$_" => { rename => 'section' } ) for 1..5; $template->set( 'list' => { testcode => \&tc_list } ); $template->set( code => { pre => '', post => '' } ); $template->set( strong => { pre => '', post => '' } ); $template->set( emphasis => { pre => '', post => '' } ); $template->set( verbatim => { rename => 'screen' } ); $template->set( title => { showtag => 1, testcode => \&tc_title } ); sub tc_title { my ( $n, $t ) = @_; my $abbrev; if ( $n->parentNode->getName eq "sect1" ) { ( $abbrev ) = eval { split '-', $n->childNodes->[0]->toString, 2 }; } $t->set({ post => "$abbrev" }) if $abbrev; return $n->findvalue( 'text()' ) eq 'DESCRIPTION' ? $DO_NOT_PROCESS : $DO_SELF_AND_KIDS ; } sub action_sect1 { my( $n, $t ) = @_; my $title = $n->findvalue( 'title/text()' ); if ( $title eq 'DESCRIPTION' ) { $t->set({ pre => '', showtag => 0 }); } return $title eq 'NAME' ? $DO_NOT_PROCESS : $DO_SELF_AND_KIDS ; } $template->set( 'item' => { showtag => 0 } ); $template->set( 'itemtext' => { showtag => 0 } ); sub tc_list { my ( $n, $t ) = @_; my $output; #if ( $n->findnodes( 'item/itemtext' ) ) { # we are a variable list # $output = ''; # for my $c ( $n->findnodes('item') ) { # my $item = ''; # $item .= '' . $c->findvalue( 'term/text()' ) . ''; # $item .= ''; # $item .= $processor->apply_templates( $c ); # $item .= ''; # $item .= ''; # $output .= $item; # } # $output .= ''; #} #else { # we are a itemized list $output = ''; for ( $n->findnodes( 'item' ) ) { $output .= '' . $processor->apply_templates( $_ ) . '' ; } $output .= ''; #} $t->{pre} = $output; return $DO_SELF_ONLY; } 'end of Pod::Manual::PodXML2Docbook';