Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Using XML::Saxon::XSLT2 Errors

by Anonymous Monk
on Jun 27, 2013 at 20:22 UTC ( #1041092=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am currently trying to use the XSLT2 module in a perl script. I am currently getting an error when running the script due to including this module. The main error statement is "Transformer.java:1: error: package net.sf.saxon.s9api does not exist". I'm assuming this means that when I installed XML::Saxon::XSLT2, it didn't know where the Saxon jar file was. I have it on my computer but I'm not sure how to get Inline::Java or XSLT2 to recognize that it's there or install it or do whatever I have to do. Sorry, I don't really know too much about Java and classpaths and what not so I'm sort of in the black on this issue.

Comment on Using XML::Saxon::XSLT2 Errors
Replies are listed 'Best First'.
Re: Using XML::Saxon::XSLT2 Errors
by runrig (Abbot) on Jun 27, 2013 at 21:01 UTC
    I see this code in the source for the library (XML/Saxon/XSLT2.pm):
    foreach my $path (qw( /usr/share/java/saxon9he.jar /usr/local/share/java/saxon9he.jar /usr/share/java/saxonb.jar /usr/local/share/java/saxonb.jar)) { $classpath = $path if -e $path; last if defined $classpath; }

    It looks like it expects the jar file in one of those paths. If your jar file is not in any of those, go ahead and edit the source and add your path to the list. That's my guess anyway...

    If I were to rewrite this, I would make it configurable via (at least) some environment variable, maybe SAXON_LIB_PATH or something...rather than just a hard coded list of paths

      It is already configurable. Look a few lines further down at the import method:

      sub import { my ($class, @args) = @_; shift @args if @args && exists $args[0] && defined $args[0] && $args[0] =~ + /^[\d\.\_]{1,10}$/; Inline->import(Java => 'DATA', CLASSPATH=>$classpath, @args); }

      So the CLASSPATH => $classpath can be overridden by passing arguments to import a la:

      use XML::Saxon::XSLT2 CLASSPATH => "/path/to/saxonb.jar";

      There is an example of providing arguments to the import method in the documentation (though not the CLASSPATH argument).

      However I've not played with it much. If your application contains multiple instances of "use XML::Saxon::XSLT2" it's probably only the first one that counts. To be sure, you can supply the path on the command line like:

      perl -MXML::Saxon::XSLT2=CLASSPATH,/path/to/saxonb.jar myscript.pl

      PS: patches would be appreciated for this issue (or indeed for RT#66278 which is a long running one).

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
        Ah, I was misled by this comment in the docs:
        It expects Saxon to be installed in either '/usr/share/java/saxon9he.jar' or '/usr/local/share/java/saxon9he.jar'.

        Anyway, I'm unlikely to submit any patches since I'm not the one trying to use the library :-)

      Where are those paths? In my Java directory or in my Strawberry Perl one? Also, if I want it to just reference a path inside the module folder then how would I go about doing that?

        They're absolute paths. So on Windows, you'd probably want something starting with "C:\..."

        package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: Using XML::Saxon::XSLT2 Errors
by Samantabhadra (Initiate) on Feb 23, 2016 at 14:53 UTC
    Revered monks,

    XML::Saxon::XSLT2 is, as far as could see, the only Perl module on CPAN which processes stylesheets written in XSLT 2.0. It is therefore the module to use, if one wants to take advantage of the XSLT 2.0 stylesheets provided by the TEI Consortium for the transformation of xml-files structured according to the TEI Convention (http://www.tei-c.org/Tools/Stylesheets). Being the result of a decade's work and experience with TEI xml, the use of these stylesheets in a Perl environment seems quite advisable.

    Users of Ubuntu 14+ are in the privileged position to simply install http://packages.ubuntu.com/trusty/perl/libxml-saxon-xslt2-perl. For the time being, I am on a Ubuntu 12 server and I am stuck with the error given below.

    As the earlier error reports here (and the documentation of XML::Saxon::XSLT2) point out, one has to make sure that the module Inline::Java is installed and that the file saxonhe9.jar is present in, e.g., the directory /usr/share/java. After a good day's work, I am very sure about these two requirements. Still, my script stops in the last line given below.

    use XML::Saxon::XSLT2; use Inline::Java; # not necessary my $xml_file = "/some/defintely/existing/file.xml"; my $xslt_file = "/another/definetly/existing/file.xsl"; open(my $input, '<:encoding(UTF-8)', $xml_file) or die $!; open(my $xslt, '<:encoding(UTF-8)', $xslt_file ) or die $!; my $trans = XML::Saxon::XSLT2->new($xslt);

    I am getting the following errror:

    Can't locate object method "new" via package "XML::Saxon::XSLT2::Transformer" (perhaps you forgot to load "XML::Saxon::XSLT2::Transformer"?) at /usr/local/share/ perl/5.14.2/XML/Saxon/XSLT2.pm line 53, <$xslt> line 1.'

    The module XML::Saxon::XSLT2::Transformer doesn't exist. XSLT2.pm, line 53 reads:

        return bless { 'transformer' => XML::Saxon::XSLT2::Transformer->new($xslt) }, $class;

    I would be very grateful for any idea about what could be wrong. SERVER_SOFTWARE : Apache/2.2.22 (Ubuntu). The permissons of /usr/share/java/saxonhe9.jar are: -rwxr-xr-x

    Thank you!
      Monks,

      in a rather solipstic continuation of solving this problem, I document the following for future stranded adepts.

      First, see what the developer of XML::Saxon::LibXSLT2 has to say on Stackoverflow

      Make sure to follow his advise verbosely. As, e.g., for the notorius saxon9he.jar, the developer has used version 9.5.1.7. If you use a version from 9.6. onwards you will get a "depricated" warning in the tests mentioned below. After replacing the recent saxon9he.jar with an earlier version this warning vanishes.

      Testing the mainly concerned modules independently is enlighting (take, e.g., XML::Saxon::XSLT2 testcase or the "Synopsis" from Inline::Java.

      I run this tests on my local PC (Ubuntu 14.04.4 LTS: trusty) and on my server (Ubuntu 12.04.5 LTS: precise). On trusty I installed the concerned modules from the repositories, on precise I installed the concerned modules manually (make file and CPAN).

      On trusty both modules work as expected, on precise the tests first result in a server error when calling the testfunction with the browser.

      "Couldn't find an appropriate DIRECTORY for Inline to use"

      Clear. Inline::Java generates at first run the directory "_Inline" in order to its magic. See "The Inline 'directory'" in Inline. By attributing appropriate permissions to the _Inline directory this particular server error vanishes. (I attributed "drwxrwxrwx".)

      With this, the test is successfull from the terminal. But while on trusty the output is printed as desired, on precise the terminal prints "XML::LibXML::Document=SCALAR(0x2a0d6f8)" instead and by calling the testfunction with the browser I stuck again with the error:

      "Can't locate object method "new" via package "XML::Saxon::XSLT2::Transformer ... XSLT2.pm, line 53, line 6".

      Line 53 of XSLT2.pm reads:

      return bless { 'transformer' => XML::Saxon::XSLT2::Transformer->new($xslt) }, $class;

      It looks like the java function in XSLT2.pm, line 377 is not accessed porperly. But why?

      TobyInk, the developer of the module mentions in his comment on stackoverflow (see link above), that the JAVA_HOME environment is needed to be set.

      "echo $JAVA_HOME" remains silent on both, trusty and precise. However, I set JAVA_HOME anyway (with this how to). Still, the same error.

      Any help greatly appreciated.

        Stupid question, but is java even installed?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1041092]
Approved by runrig
Front-paged by runrig
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2016-05-29 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?