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

XML::XSLT problem

by artist (Parson)
on Nov 16, 2006 at 20:54 UTC ( #584600=perlquestion: print w/ replies, xml ) Need Help??
artist has asked for the wisdom of the Perl Monks concerning the following question:

Here is my code.
use XML::XSLT; use strict; use warnings; my $xsl = 'sample.xsl'; my $xmlfile = 'sample.xml'; my $xslt = XML::XSLT->new($xsl, warnings => 1);
It generates the message: Can't locate object method "new" via package "XML::XSLT" (perhaps you forgot to load "XML::XSLT"?) at program.pl line 6.

From docs, I get

XML::XSLT makes use of XML::DOM and LWP::Simple, while XML::DOM uses XML::Parser. Therefore XML::Parser, XML::DOM and LWP::Simple have to be installed properly for XML::XSLT to run.
By checking the modules with CPAN, I get following results:
XML::Parser is up to date (2.34).
XML::DOM is up to date (1.44).
LWP::Simple is up to date (1.41)

I might be missing something obvious, but cannot figure it out myself...

--Artist

Comment on XML::XSLT problem
Download Code
Re: XML::XSLT problem
by bmann (Priest) on Nov 16, 2006 at 22:15 UTC
    Is XML::XSLT up to date? Old versions (0.20 and earlier) don't have a new method.

      I am using version 0.48 for XML::XSLT as recently downloaded from CPAN. I copied that in my home directory and now, I get the message : Can't call method "createDocumentFragment" on an undefined value at XML/XSLT.pm line 766.

      --Artist
        
        

        This sounds like you are trying to process a stylesheet without having loaded an XML document first. Please could you supply the smallest piece of code and sample XML and XSLT files that give this error - I'm pretty sure the code you have above wouldn't do this because it XML::DOM's createDocumentFragment() is only used when certain XSLT directives need to insert generated elements into the outout document.

        BTW don't bother following up the cpanforum posting, I'm not going to respond in both places.

        /J\

Re: XML::XSLT problem
by graff (Chancellor) on Nov 17, 2006 at 02:12 UTC
    It may be that there is an older version of XML::XSLT (lacking the "new" method) already installed somewhere in a "default" @INC path, and your perl script will always find that first.

    Try twiddling with @INC before loading the module -- e.g. put the path having the current version of the module in your PERL5LIB environment variable or on the shebang line: "-I/path/to/new/version".

    I haven't looked at the docs yet about how the various path settings are ordered at start-up, but I think one of those methods will do an "unshift" of the given path onto @INC (i.e. put it at the front of the list).

    As a last resort, you could do something like this in your script:

    # instead of use XML::XSLT; ... unshift @INC, "/path/to/new/version"; require XML::XSLT;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-12-27 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls