Hello Monks,

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:
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();
and my XSLT file "main.xsl" looks like :
<?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>
When i run my pl from command prompt i get following error:
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

In reply to XSLT to HTML/XHTML by tej

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.