Hello, I'm trying to create a text file from some XML using Lib::XSLT, my transformation works fine except Lib::XSLT adds an extra <?xml version="1.0"?> line to the start of the file, how can I stop it doing this? Here's my XSLT:
<xslt:stylesheet version="1.0" xmlns:data="http://www.SDMX.org/resourc +es/SDMXML/schemas/v2_0/generic" xmlns:xslt="http://www.w3.org/1999/XS +L/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xm +lns:message="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/messag +e" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" omit-xml-declaration="yes"/> <xslt:param name="sep">|</xslt:param> <xslt:output method="text" /> <xslt:template match="message:MessageGroup"> <xslt:for-each select="data:DataSet"> <!-- get dimensions (but not time) and store in dimensions variable -- +> <xslt:for-each select="data:Series"> <xslt:variable name="dimensions"> <xslt:for-each select="data:SeriesKey"> <xslt:for-each select="data:Value"> <xslt:value-of select="@value" /> <xslt:value-of select="$sep" /> </xslt:for-each> </xslt:for-each> </xslt:variable> <!--get obs statuses and store in obs statuses variable--> <xslt:variable name="obsStatuses"> <xslt:for-each select="data:Attributes"> <xslt:for-each select="data:Value"> <xslt:value-of select="@value" /> </xslt:for-each> </xslt:for-each> </xslt:variable> <!--write out dimensions variable, time, observation, obsstatuses vari +able--> <xslt:for-each select="data:Obs"> <xslt:value-of select="$dimensions" /> <xslt:value-of select="data:Time" /> <xslt:value-of select="$sep" /> <xslt:value-of select="data:ObsValue/@value" /> <xslt:value-of select="$sep" /> <xslt:value-of select="data:Attributes/data:Value/@value"/> <xslt:text> </xslt:text> </xslt:for-each> </xslt:for-each> </xslt:for-each> </xslt:template> </xslt:stylesheet>
Here's the Perl:
my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); my $source = XML::LibXML->load_xml(location => "$xmlFile"); my $style_doc = $parser->parse_file(Path::Class::File->new("$xsltF +ile")); my $stylesheet = $xslt->parse_stylesheet($style_doc); open OUTPUTFILE, ">>$outputFile" or die("Unable to open $outputFil +e, $!"); print OUTPUTFILE $stylesheet->transform($source); close OUTPUTFILE;

In reply to Unwanted <?xml> tags with Lib::XSLT by aeolai

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.