Registered function not directly selectable?
by Elizabeth Mattijsen other posts by this author
Jun 18 2007 8:41AM messages near this date
view in the new Beta List Site
Re: regex for xml comment.
|
Re: Registered function not directly selectable?
& XSLT This came up while migrating a 3+ year old XML::LibXML/LibXSLT
application for a client to the latest and greatest versions.
It seems now that registered functions cannot be selected upon
directly in XML::LibXSLT. Not sure whether this is a problem in
XML::LibXSLT or in libxslt2, but I'm guessing the former for now.
In short:
<xsl:copy-of select="foo:custom()/foo"/>
produces garbage on serialization, whereas:
<xsl:variable name="custom" select="foo:custom()" />
<xsl:copy-of select="$custom/foo"/>
works as expected.
I would appreciate any ideas, comments, workaround (other than the
one above, as we're talking many 1000's lines that would need to be
changed).
Elizabeth Mattijsen
____________________________________
A little more elaborate, for those of you really interested, take the
following script:
====================================
use strict;
use warnings;
use XML::LibXML;
use XML::LibXSLT;
print "XML::LibXML = $XML::LibXML::VERSION\n";
print "XML::LibXSLT = $XML::LibXSLT::VERSION\n";
print "libxml2 = " . XML::LibXML::LIBXML_DOTTED_VERSION . "\n";
print "libxslt2 = " . XML::LibXSLT::LIBXSLT_DOTTED_VERSION . "\n";
my $parser = XML::LibXML-> new;
my $xsltproc = XML::LibXSLT-> new;
XML::LibXSLT-> register_function( 'http://foo', 'custom', sub {
return $parser-> parse_string( <<'XML' )->findnodes('/*');
<bar>
<foo> One Foo</foo>
</bar>
XML
} );
my $xml = $parser-> parse_string( <<'XML' );
<html>
<head>
</head>
</html>
XML
my $xslt = $parser-> parse_string( <<'XSLT' );
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="http://foo"
version="1.0"
>
<xsl:template match="/html">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="/html/head">
<head>
<xsl:copy-of select="foo:custom()/foo"/>
<xsl:apply-templates/>
</head>
</xsl:template>
</xsl:stylesheet>
XSLT
my $stylesheet = $xsltproc-> parse_stylesheet($xslt);
my $result = $stylesheet-> transform($xml);
print $result-> serialize;
====================================
I would expect this to output:
====================================
XML::LibXML = 1.63
XML::LibXSLT = 1.62
libxml2 = 2.6.28
libxslt2 = 1.1.20
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<html xmlns:foo="http://foo">
<head> <foo>One Foo</foo>
</head>
</html>
====================================
However, it outputs something like:
====================================
XML::LibXML = 1.63
XML::LibXSLT = 1.62
libxml2 = 2.6.28
libxslt2 = 1.1.20
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<html xmlns:foo="http://foo">
<head> <X e>?Foo</X e>
</head>
</html>
====================================
where the actual string after <head> is something random.
Oddly enough, if I run this under valgrind, I *do* get the expected
output. But valgrind complains about the following repeatedly.
==13431== Invalid read of size 4
==13431== at 0x49F9D45: xsltCopyOf (in /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49F62BC: (within /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49F7822: (within /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49F801C: xsltProcessOneNode (in /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49F8CCF: xsltApplyTemplates (in /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49F62BC: (within /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49F7822: (within /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49F801C: xsltProcessOneNode (in /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49F84C6: xsltProcessOneNode (in /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49FC201: (within /usr/lib/libxslt.so.1.1.21)
==13431== by 0x49CB981: XS_XML__LibXSLT__Stylesheet_transform
(LibXSLT.xs:959)
==13431== by 0x97151C: Perl_pp_entersub (in
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so)
==13431== Address 0x496E5D4 is 4 bytes inside a block of size 60 free'd
==13431== at 0x400501A: free (vg_replace_malloc.c:233)
==13431== by 0x446121A: xmlFreeNodeList (in /usr/lib/libxml2.so.2.6.29)
==13431== by 0x4461135: xmlFreeNodeList (in /usr/lib/libxml2.so.2.6.29)
==13431== by 0x448BC67: (within /usr/lib/libxml2.so.2.6.29)
==13431== by 0x448CF91: (within /usr/lib/libxml2.so.2.6.29)
==13431== by 0x4499A71: (within /usr/lib/libxml2.so.2.6.29)
==13431== by 0x4497EB0: (within /usr/lib/libxml2.so.2.6.29)
==13431== by 0x44977AB: (within /usr/lib/libxml2.so.2.6.29)
==13431== by 0x4499408: (within /usr/lib/libxml2.so.2.6.29)
==13431== by 0x449DA25: (within /usr/lib/libxml2.so.2.6.29)
==13431== by 0x449DC31: xmlXPathCompiledEval (in /usr/lib/libxml2.so.2.6.29)
==13431== by 0x49F9B51: xsltCopyOf (in /usr/lib/libxslt.so.1.1.21)
etc. etc.
Running the application under valgrind in production is not an
option, I'm afraid... ;-)
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Elizabeth Mattijsen
Elizabeth Mattijsen
Elizabeth Mattijsen
Petr Pajas
Elizabeth Mattijsen
Petr Pajas
Elizabeth Mattijsen
Nicolas Mendoza
|