tej has asked for the wisdom of the Perl Monks concerning the following question:
I have an XSLT stylesheet which helps me to convert XML to HTML.
I want to execute this stylesheet through perl. When I run it on Stylus Editor It works fine without any error.
I tried using XML::XSLT and my code looks like:and my XSLT file "main.xsl" looks like :use XML::XSLT; my $xsl="main.xsl"; my $xmlfile="main.xml"; my $xslt = XML::XSLT->new ($xsl, warnings => 1); $xslt->transform ($xmlfile); print $xslt->toString; $xslt->dispose();
When i run my pl from command prompt i get following error:<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="http://www.w3schools.com/furniture"> <xsl:output method="html" encoding="ANSI_X3.4-1986"/> <xsl:template match="chapter"> <html> <body> <div class="chap-title"><xsl:value-of select="f:title"/></div> <xsl:apply-templates select="f:sections"/> <!--<xsl:apply-templates select="f:bibliography"/>--> </body> </html> </xsl:template> <xsl:template match="f:section/f:section-title"> <div class="hd1"><br></br><xsl:value-of select="."/></div> </xsl:template> <xsl:template match="f:sections/f:section/f:para/text()"> <!--<xsl:apply-templates/>--> <div class="para1"><xsl:value-of select="."/></div> </xsl:template> <xsl:template match="f:section/f:section/f:section-title"> <div class="hd2"><br></br><xsl:value-of select="."/></div> </xsl:template> <xsl:variable name="level">0</xsl:variable> <xsl:template match="//f:list"> <xsl:variable name="val"> <xsl:number value="position()"/> </xsl:variable> <xsl:call-template name="recursive"> <xsl:with-param name="f:list"/> </xsl:call-template> </xsl:template> <xsl:template name="recursive" match="//f:list"> <xsl:param name="f:list" select="f:list-item"/> <xsl:for-each select="f:list-item"> <xsl:value-of select="/f:para"/><br></br> <div class="lt1"></div> <xsl:apply-templates/> </xsl:for-each> </xsl:template> <xsl:template match="f:section/f:section/f:section/f:section/f:section +-title"> <div class="hd3"><xsl:value-of select="."/></div> </xsl:template> <xsl:template match="f:sections/f:section/f:section/f:section/f:sectio +n/f:section-title"> <div class="hd3"><xsl:value-of select="."/></div> </xsl:template> <xsl:template match="f:sections/f:section/f:section/f:section/f:sectio +n-title"> <div class="hd4"><br></br><xsl:value-of select="."/></div> </xsl:template> </xsl:stylesheet>
Can't call method "createDocumentFragment" on an undefined value at C +:/Perl/site /lib/XML/XSLT.pm line 766.
I dont understand what can be the problem..I tried searching a lot and probably it is in my xsl file. What can the possible error?
Also like We have toString method is there any method which I can use to create output file? Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XSLT to HTML/XHTML
by duyet (Friar) on Aug 05, 2011 at 08:32 UTC | |
by tej (Scribe) on Aug 05, 2011 at 09:17 UTC | |
by duyet (Friar) on Aug 05, 2011 at 10:17 UTC | |
|
Re: XSLT to HTML/XHTML
by Anonymous Monk on Aug 05, 2011 at 07:10 UTC | |
by tej (Scribe) on Aug 05, 2011 at 07:16 UTC | |
by bart (Canon) on Aug 05, 2011 at 11:08 UTC |