| 1 |
#!/usr/local/bin/perl -w |
| 2 |
|
| 3 |
# $Id: xslt-parser,v 1.9 2001/03/01 05:22:45 hexmode Exp $ |
| 4 |
|
| 5 |
use strict; |
| 6 |
use XML::XSLT; |
| 7 |
use Getopt::Std; |
| 8 |
|
| 9 |
=head1 NAME |
| 10 |
|
| 11 |
xslt-parser - XSLT transformations |
| 12 |
|
| 13 |
=head1 SYNOPSIS |
| 14 |
|
| 15 |
xslt-parser [options] <project> |
| 16 |
|
| 17 |
=head1 DESCRIPTION |
| 18 |
|
| 19 |
xslt-parser performs stylesheet transformations. |
| 20 |
|
| 21 |
When given a project name, it appends `.xsl' for the XSLT stylesheet |
| 22 |
and `.xml' for the XML file to apply the stylesheet to and performs the |
| 23 |
transformation using the XML::XSLT perl module. |
| 24 |
|
| 25 |
=head1 OPTIONS |
| 26 |
|
| 27 |
=over 4 |
| 28 |
|
| 29 |
=item -c |
| 30 |
|
| 31 |
Pass through HTML::Clean. You must have HTML::Clean installed. |
| 32 |
|
| 33 |
=item -d |
| 34 |
|
| 35 |
Turns debugging on. This can produce a lot of noise. |
| 36 |
|
| 37 |
=item -n |
| 38 |
|
| 39 |
NoWeb. You can use xslt-parser as a CGI script. With this option, |
| 40 |
it will not output the headers that are usually needed. |
| 41 |
|
| 42 |
=item -s <file> |
| 43 |
|
| •44 |
Specify a separate different stylesheet. Usually, xslt-parser will |
| 45 |
simply append `.xsl' to the project name to get the stylesheet. A |
| 46 |
different stylesheet can be specified using this option. |
| 47 |
|
| •48 |
=back |
| 49 |
|
| 50 |
=head1 AUTHORS |
| 51 |
|
| 52 |
Geert Josten <[email protected]>, |
| 53 |
Mark A. Hershberger <[email protected]> |
| 54 |
|
| 55 |
=head1 SEE ALSO |
| 56 |
|
| 57 |
L<XML::XSLT> |
| 58 |
|
| 59 |
The w3.org XSLT recommendation at L<http://www.w3.org/TR/xslt> |
| 60 |
|
| 61 |
=cut |
| 62 |
|
| 63 |
my %opt; |
| 64 |
my $usage = "Usage: $0 [options] <project> |
| 65 |
|
| 66 |
-d turn debugging mode on |
| 67 |
-n don't print content-type |
| 68 |
-s <file> use <file> instead of <project>.xsl as template |
| 69 |
-w turns warnings on\n"; |
| 70 |
getopts('cdnws:h', \%opt) || die $usage; |
| 71 |
|
| 72 |
die $usage if $opt{h}; |
| 73 |
|
| 74 |
## global vars ## |
| 75 |
my $noweb = $opt{n} || 0; |
| 76 |
my $debug = $opt{d} || 0; |
| 77 |
my $warnings = $opt{w} || 0; |
| 78 |
my $project = shift || die $usage; |
| 79 |
my $xslfile = $opt{'s'} || "$project.xsl"; |
| 80 |
my $xmlfile = $project; |
| 81 |
|
| 82 |
my $xslt = XML::XSLT->new (Source => $xslfile, |
| 83 |
debug => $debug, |
| 84 |
warnings => $debug); |
| 85 |
|
| 86 |
if (! -f $xslfile) { |
| 87 |
die "$xslfile does not exist."; |
| 88 |
} |
| 89 |
|
| 90 |
if (! -f $xmlfile) { |
| 91 |
$xmlfile .= ".xml"; |
| 92 |
if (! -f $xmlfile) { |
| 93 |
die "$xmlfile does not exist." |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
print STDERR qq{Debug : "$debug" |
| 98 |
NoWeb : "$noweb" |
| 99 |
Warnings: "$warnings" |
| 100 |
Project : "$project" |
| 101 |
XML-file: "$xmlfile" |
| 102 |
XSL-file: "$xslfile" |
| 103 |
} if $debug; |
| 104 |
|
| 105 |
print $xslt->serve(Source => $xmlfile, |
| 106 |
clean => $opt{c}, |
| 107 |
http_headers => ! $noweb); |
| 108 |
|