Subject: | Passing XML document from Perl + exslt:node-set causes weird behavior |
This is a copy of GNOME Bugzilla bug #562302 filed by Alexander Schepanovski against libxslt:
https://bugzilla.gnome.org/show_bug.cgi?id=562302
-------------------------------------------------
Perl code making trouble:
#!/usr/bin/perl
use XML::LibXML;
use XML::LibXSLT;
my $parser = new XML::LibXML;
my $xslt = new XML::LibXSLT;
# registering function
my $doc;
sub cfg {
my $xml = q~<?xml version="1.0"
encoding="utf-8"?><xml_storage></xml_storage>~;
return $doc = $parser->parse_string($xml);
}
XML::LibXSLT->register_function("urn:perl", 'cfg', \&cfg);
# loading and parsing stylesheet
my $style_doc = $parser->parse_file("skeleton.xsl");
my $stylesheet = $xslt->parse_stylesheet($style_doc);
# performing transform
my $source = new XML::LibXML::Document;
my $results = $stylesheet->transform($source);
# writing result
open F, ">result.xml" or die;
print F $stylesheet->output_string($results);
close F;
Where skeleton.xsl is:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
xmlns:perl="urn:perl"
exclude-result-prefixes="exslt perl">
<xsl:variable name="xml_storage" select="perl:cfg()/xml_storage" />
<xsl:variable name="page-data-tree">
<title><xsl:value-of select="$xml_storage"/></title>
<crumbs>
<page><url>hello</url></page>
<page><url>bye</url></page>
</crumbs>
</xsl:variable>
<xsl:variable name="page-data" select="exslt:node-set($page-data-tree)" />
<xsl:template match="/">
<result><xsl:value-of select="$xml_storage"/></result>
</xsl:template>
</xsl:stylesheet>
Result is
<?xml version="1.0"?>
<result>bye</result>
It seems that value of $xml_storage varies depending on its use in diffrent
part of xsl stylesheet. It also depend on its true value passed from perl.
Varying stylesheet and xml document passed from perl, you can even get
segfault.