vladb has asked for the wisdom of the Perl Monks concerning the following question:

Thanks for taking your time to hear to my concern.

I've been recently playing with some XSLT for various templating and other reasons. I have also spent some time on the web trying to learn about the beast and also how it is used in Perl. Unfortunately, I couldn't find plenty good information on the use of the XML::XSLT perl module. Not even in the native perldoc! ;/.

Anyhow, could you please explain me what is wrong with this code? This is the real deal and only used for testing purposes while I'm still learning how to use XML::XSLT. So, in this example, I'm first parsing an XML 'string' (saved in a scalar variable), which works just fine. Next, I'm trying to parse an XSL file 'Data/verysimple.xsl' that contains the exact same XSL 'string'. However, this second time the parser reports this error (this is the script's output actually):
XSL string parsed! Error while parsing: not well-formed (invalid token) at line 1, column 4, byte 4 at /Citygu +ides/local/lib/perl5/site_perl/5.6.1/sun4-solaris/XML/Parser.pm line +185 Data/verysimple.xml at /export/home/vlad/scratch/LIB/XML/XSLT.pm line +1150.
Here's the actual code:
use XML::XSLT; my $simple_xsl = qq~<?xml version="1.0"?> <xsl:stylesheet> <xsl:template match="/"> <html> <xsl:apply-templates/> </html> </xsl:template> </xsl:stylesheet> ~; my $source = new XML::XSLT($simple_xsl); print "XSL string parsed!\n"; my $source1 = new XML::XSLT('Data/verysimple.xml'); print "XSL file parsed!\n";


Update: Thanks for all your comments. In fact all of the comments are correct. In this particular instance, I indeed failed to provide proper file name. Nontheless, the module couldn't parse any other xml file (actual deal) that I had to parse. Also, it had very poor error reporting (say, if I made a syntax error in my XML at line 100 or so, it would still continue saying that the error is at line 1 ;/). I've now installed libxml2 and libxsml libraries and also trying to install XML::LibXML and XML::LibXSLT as per your comments. I'm sincerely appreciative of your support! :-)

_____________________
# Under Construction

Replies are listed 'Best First'.
Re: XSLT doesn't understand me?
by Matts (Deacon) on Jun 28, 2002 at 10:36 UTC
    You don't tell us what's in "Data/verysimple.xml" - that is where the problem is occuring. The file is obviously not XML.

    But I also can't recommend strongly enough to NOT USE XML::XSLT. Sorry for shouting that, but it needs to be said. This is a very bad module that does not implement XSLT, but a very *very* small subset of it, and the parts that it does implement are often done wrongly. In short, steer clear, and go for XML::LibXSLT, XML::Sablotron, or XML::Xerces.

Re: XSLT doesn't understand me?
by newrisedesigns (Curate) on Jun 27, 2002 at 19:35 UTC

    I highly doubt this is the problem, but you said "data/verysimple.xsl", and your code has "xml".

    Does it work if you pass it the string, like so:

    my $source1 = new XML::XSLT($simple_xsl);

    Hope this helps.

    John J Reiser
    newrisedesigns.com

Re: XSLT doesn't understand me?
by lestrrat (Deacon) on Jun 27, 2002 at 19:17 UTC

    Update: I need to read the question more closely before answering. ugh

    Perhaps it requires a XML namespace declaration before using "xsl:" ?

    In either case, seeing that this module hasn't been updated since the end of last year (according to CPAN), you might want to try XML::LibXML and XML::LibXSLT which are much much more actively maintained.

Re: XSLT doesn't understand me?
by thraxil (Prior) on Jun 28, 2002 at 14:26 UTC

    Matts and newrisedesigns are probably onto the problem. if i run the code snippet on my machine without creating the file 'Data/verysimple.xml', i get exactly the same output as you've shown. this would suggest to me that the file 'Data/verysimple.xml' doesn't exist on your system or isn't readable.

    anders pearson