aeolai has asked for the wisdom of the Perl Monks concerning the following question:
Here's the Perl:<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>
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unwanted <?xml> tags with Lib::XSLT
by tobyink (Canon) on Jul 03, 2012 at 14:15 UTC | |
by aeolai (Initiate) on Jul 03, 2012 at 15:28 UTC | |
by aeolai (Initiate) on Jul 05, 2012 at 22:53 UTC |