Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: XML::XSLT problem

by rg0now (Chaplain)
on Apr 24, 2005 at 16:13 UTC ( [id://450994]=note: print w/replies, xml ) Need Help??


in reply to XML::XSLT problem

You do not want to read the contents of the XML file, just to apply the XSLT to it. Simply pass the name of the file to the transform method: (snippet taken from the man page of XML::XSLT):
use XML::XSLT; my $xslt = XML::XSLT->new ($xsl, warnings => 1); $xslt->transform ($xmlfile); print $xslt->toString;
This has the beneficial side-effect, that you will (hoepfully) get more descriptive error messages...

Replies are listed 'Best First'.
Re^2: XML::XSLT problem
by bosshoff (Novice) on Apr 24, 2005 at 17:08 UTC
    I already tried that, and here is the new code:

    use strict; use XML::XSLT; myy $xslt = XML::XSLT->new ("blog.xsl", warnings => 1, debug => 1); $xslt->transform ("posts.xml"); print $xslt->toString; $xslt->dispose();
    Alas, same error. I was already making sure that the files did exist and that the variables were being filled, by outputing the vars; I know this isn't a simple file I/O error, in other words.

    What I find rather funny is that, when I use the deprecated document_transform function, it kindof works; it prints out only the first template match="/" stylesheet declaration and nothing else.

    Furthermore, I know it isn't my XSL or XML files because Xalan works flawlessly. There must be something I'm doing wrong, I just can't find out what, and that error message is not very descriptive (couldn't find anything at byte -1, really? lol)
      Ok, now the only thing remained to be done is to have a look at your actual blog.xsl and posts.xml files. A useful way to tackle these kinds of problems is if you try to find the minimal working and non-working examples, which then can be posted here. My guess is that either your XSL or XML is invalid, since the problem seems to rise right at the first line. You might not have the usual <xsl:stylesheet version="1.0" blablabla at the first line? Try to find some very basic XML and XSL files that do not work and try to find, what makes your specific version to fail.

      I myself have often found the solution for various problems just to try to create a basic test case, which can be posted to PerlMonks...

        I will prepare these test cases, but I've alread mentioned that these files work flawlessly with Xalan, which is a C-based validating XSLT processor. I assume that XML::XSLT is keeping with the same standard. Also, if it were simply a problem with the xsl/xml, wouldn't you think there would be a more descriptive error, such as: "element illegal" or "element {some element} not found" as opposed to a generic "element not found," as if there was no input at all?

        If anyone else has had success with XML::XSLT, please post your code; I'm certain I am just doing something wrong when calling it, but I don't know what. Thanks.

        Oh, and here are the links for my current .xsl and .xml files:
        XSL XML

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://450994]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found