#!/usr/bin/perl -w # Author: Michel Rodriguez use strict; use XML::LibXSLT; use XML::LibXML; my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); my $source = $parser->parse_file('/article/ways_to_rome/ex_ps_libxslt/REC_xml_19980210.xml'); my $style_doc = $parser->parse_file('/article/ways_to_rome/ex_ps_xslt.xslt'); my $stylesheet = $xslt->parse_stylesheet($style_doc); my $results = $stylesheet->transform($source); set_filter(); # sets the post-processing filter print $stylesheet->output_string($results); # filter applied to the output of the XSLT transformation sub set_filter { return if my $pid= open( STDOUT, "|-"); # magic open die "cannot fork: $!" unless defined $pid; $|=1; my $prod=''; while( ) { if( m/^\s*\[\d+\]/) # found the beginning of a production { print( clean($prod), "\n") if( $prod=~ /\S/); $prod= ''; } $prod .= $_; } print clean( $prod),"\n"; exit; } sub clean { my( $string)= @_; $string =~ s/\xc2\xa0/ /sg; $string =~ s/\s+/ /g; $string=~ s{\s$}{}; $string=~ s{^\s}{}; return $string; }