[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Calling Java Xalan inside Perl on Unix

Subject: Re: Calling Java Xalan inside Perl on Unix
From: David McKain <dmckain1@xxxxxxxxxxx>
Date: Thu, 17 Apr 2003 16:42:13 +0100
perl xalan
On Thu, Apr 17, 2003 at 10:07:42AM -0400, Gan Uesli Starling wrote:
> 
> Anybody know how to call Xalan from a Perl script on
> NetBSD Unix? I can't seem to get it right. I try like
> so in my Perl script...
>
Hi Gan,

> @xsl = ("java", "org.apache.xalan.xslt.Process -in 
> $file_name.xml -xsl pdfmarks.xsl -out pdfmarks.txt");
> system(@xsl);

Your problem is shell escaping. The list @xsl you pass to system() has 2
arguments so is equivalent to typing:

java "org.apache.xalan.xslt.Process -in blah.xml blah..."

at the shell (I've omitted the last part of the command to make it fit
on one line!)

Everything inside the double quotes is treated as ONE argument by the
shell, so what this does is ask Java to find and run the class called
org.apache.xalan.xslt.Process -in blah.xml blah... This class
name includes the space and the '-in' stuff and almost certainly doesn't
exist, hence the error.

To fix, do:

my @xsl = ("java", "org.apache.xalan.xslt.Process", "-in",
            "$filename.xml", ...);
system(@xsl);

Each member of the list @xsl represents a separate command line argument,
which is what you want here.

This particular example can also be written in a less noisy but entirely
equivalent way using Perl's "quote words" qw(...) quoting as:

my @xsl = qw(java org.apache.xalan.xslt.Process -in $filename.xml ...)

Alternatively, use the less safe 'system COMMAND' method:

system("java org.apache.xalan.xslt.Process -in ...");

though do bear in mind that you must be *very* careful about using this
last method if any of the strings being interpolated into the system
command are not hardcoded into your program, as otherwise you may end up
executing

java org.apache.xalan.xslt.Process ; rm -rf /

which probably doesn't do what you want!

For more info, perldoc -f system

You might also want to try looking at either XML::LibXSLT or Sablotron
for XSLT processing in Perl; calling java in this way is not terribly
efficient.

Cheers,
David.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.