# -2... Specifies a particular version
# -debug Debugging
# -config Where is the config file? Defaults to ~/.xmlc
+# -c14n Canonicalize output using xmllint
# -opts id Use additional options 'id' from the config file.
# The -opts option may be specified more than once
#
my $debug = 0;
my $config = "~/.xmlc";
my @opts = ();
+my $c14n = 0;
while (@ARGV) {
if ($ARGV[0] =~ /^-\d/) {
} elsif ($ARGV[0] eq '-config') {
shift @ARGV;
$config = shift @ARGV;
+ } elsif ($ARGV[0] eq '-c14n') {
+ shift @ARGV;
+ $c14n = 1;
} elsif ($ARGV[0] eq '-opts') {
shift @ARGV;
push(@opts, shift @ARGV);
# Everything else goes to xsltproc
my @xsltprocopts = @ARGV;
-push (@xsltprocopts, "-o $output") if defined($output) && $output ne '-';
+
+# xsltproc output sometimes contains unnecessary namespace nodes;
+# piping it through "xmllint --c14n" to canonicalize the output
+# removes those
+my @xmllintopts = ("--c14n");
die $usage if !defined($input) || !defined($style);
my $doc = ($xp->find("/config")->get_nodelist())[0];
die "Unexpected root element in configuration file.\n" if !$doc;
+my $xsltprocexec;
foreach my $name (@opts, $optsname) {
- applyOpts($xp, $name);
+ $xsltprocexec = applyOpts($xp, $name);
}
showVars() if $debug;
die "No execname?\n" if !defined($execname);
my $xopts = join(" ", @xsltprocopts);
+my $xlintopts = join(" ", @xmllintopts);
my $xparam = "";
foreach my $param (@params) {
$name = $param;
}
- $xparam .= "-stringparam $name \"$value\" ";
+ $xparam .= "--stringparam $name \"$value\" ";
+}
+
+# note that there is a bug in the -o option in xsltproc; if you
+# do, for example, "xsltproc -o /dev/null foo.xsl bar.xml" with a
+# stylesheet that has exsl:document or saxon:output, xsltproc
+# tries to write the output in the /dev directory; so we need to
+# redirect the output instead of using xsltproc's -o option
+my $redirect = " > $output" if defined($output) && $output ne '-';
+
+if ($c14n) {
+ my $xmllintpipe = " | " . applyOpts($xp, 'xmllint') . " " . $xlintopts;
+ $redirect = $xmllintpipe . " - " . $redirect;
}
-print "$execname $xopts $style $input\n" if $debug;
-exec("$execname $xopts $style $input");
+print "$xsltprocexec $xopts $xparam $style $input$redirect\n" if $debug;
+exec("$xsltprocexec $xopts $xparam $style $input$redirect");
# ============================================================
print STDERR "Loading $id from $config\n" if $debug;
- $execname = $node->getAttribute('exec')
+ my $execname = $node->getAttribute('exec')
if $execname eq '';
- foreach my $arg (configArgs($node, 'arg', '-', ' ')) {
- addOpt(\@xsltprocopts, $arg, ' ');
- }
+ if ($id eq "xsltproc") {
+ foreach my $arg (configArgs($node, 'arg', '--', ' ')) {
+ addOpt(\@xsltprocopts, $arg, ' ');
+ }
+ } elsif ($id eq "xmllint") {
+ foreach my $arg (configArgs($node, 'arg', '--', ' ')) {
+ addOpt(\@xmllintopts, $arg, ' ');
+ }
+ }
foreach my $param (configArgs($node, 'param', '', '=')) {
addOpt(\@params, $param, '=');
my $extends = $node->getAttribute('extends');
applyOpts($xp, $extends) if $extends ne '';
+ return $execname;
}
sub configArgs {
print STDERR "optsname: $optsname\n";
showArr("opts", @opts);
showArr("xsltproc opts", @xsltprocopts);
+ showArr("xmllint opts", @xmllintopts) if $c14n;
print STDERR "input: $input\n" if defined($input);
+ print STDERR "output: $output\n" if defined($output);
+ print STDERR "c14n: enabled\n" if $c14n;
print STDERR "style: $style\n" if defined($style);
if (@params) {
print STDERR "params:\n";
$name = $param;
}
- print STDERR "\t-stringparam $name \"$value\"\n";
+ print STDERR "\t--stringparam $name \"$value\"\n";
}
}
}