#!/usr/bin/perl -w
=head1 NAME
change_style - Merging content & presentation from different files
=head1 SYNOPSIS
Sample program creating a new document merging the content and the
presentation of two existing documents
Usage: change_style -content file1.sxw -style file2.sxw -target file3.sxw
=head1 COMMENT
You could produce the same result, without using any XML API, by a direct
zip extraction and copy of the 'styles.xml' member from $style_file to
$content_file. But using OpenOffice::OODoc::XPath, you can ensure $target_file
is a well formed XML OpenOffice.org document. And, in a real application, you
should do more sophisticated, XML-aware controls and transformations in the
document.
Take care: If the imported style definitions include external objects (ex:
images in the page background or in headers/footers), you have to ensure the
corresponding URLs will be made available from within the target file before
editing/printing. And the named style invocations from within the text content
of $content_file must be consistent with the named style definitions of
$style_file. All that could be controlled by a more realistic program.
This sample script is of no effect on automatic styles; it plays only with
the content of 'styles.xml' (i.e. page presentation and named styles
definitions.
=cut
use OpenOffice::OODoc::XPath; # the low-level interface is sufficient here
use Getopt::Long;
my ($content_file, $style_file, $target_file) = undef, undef, undef;
# get the command line parameters
GetOptions
(
'content=s' => \$content_file,
'style=s' => \$style_file,
'target=s' => \$target_file
);
unless ($content_file && $style_file && $target_file)
{
warn "usage : merge.pl -content file1 -style file2 -target file3\n";
exit;
}
# focus on the 'styles.xml' member of each source file
my $style_doc = OpenOffice::OODoc::XPath->new(file => $style_file, member => STYLES);
my $content_doc = OpenOffice::OODoc::XPath->new(file => $content_file, member => STYLES);
# copy the presentation from $style_doc to $content_doc
$content_doc->cloneContent($style_doc);
# and save the result as $target_file
$content_doc->save($target_file);
# that's all
exit;