XML-LibXSLT
view release on metacpan or search on metacpan
lib/XML/LibXSLT.pm view on Meta::CPAN
XML::LibXSLT - Interface to the GNOME libxslt library
=head1 SYNOPSIS
use XML::LibXSLT;
use XML::LibXML;
my $xslt = XML::LibXSLT->new();
my $source = XML::LibXML->load_xml(location => 'foo.xml');
my $style_doc = XML::LibXML->load_xml(location=>'bar.xsl', no_cdata=>1);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($source);
print $stylesheet->output_as_bytes($results);
=head1 DESCRIPTION
This module is an interface to the GNOME project's libxslt. This is an
lib/XML/LibXSLT.pm view on Meta::CPAN
=item parse_stylesheet($stylesheet_doc)
C<$stylesheet_doc> here is an XML::LibXML::Document object (see L<XML::LibXML>)
representing an XSLT file. This method will return a
XML::LibXSLT::Stylesheet object, or undef on failure. If the XSLT is
invalid, an exception will be thrown, so wrap the call to
parse_stylesheet in an eval{} block to trap this.
IMPORTANT: C<$stylesheet_doc> should not contain CDATA sections,
otherwise libxslt may misbehave. The best way to assure this is to
load the stylesheet with no_cdata flag, e.g.
my $stylesheet_doc = XML::LibXML->load_xml(location=>"some.xsl", no_cdata=>1);
=item parse_stylesheet_file($filename)
Exactly the same as the above, but parses the given filename directly.
=back
=head1 Input Callbacks
To define XML::LibXSLT or XML::LibXSLT::Stylesheet specific input
lib/XML/LibXSLT/Quick.pm view on Meta::CPAN
sub new
{
my $class = shift;
my $args = shift;
my $xslt = ( $args->{xslt_parser} // XML::LibXSLT->new() );
my $xml_parser = ( $args->{xml_parser} // XML::LibXML->new() );
my $style_doc = $xml_parser->load_xml(
location => $args->{location},
no_cdata => ( $args->{no_cdata} // 0 ),
);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $obj = bless( +{}, $class );
$obj->{xml_parser} = $xml_parser;
$obj->{stylesheet} = $stylesheet;
return $obj;
}
sub _write_utf8_file
{
}
{
# test work-around for rt #29572
my $parser = XML::LibXML->new();
my $source = $parser->parse_string(<<'EOT');
<some-xml/>
EOT
my $style_doc = $parser->load_xml(string=><<'EOT2',no_cdata=>1);
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/" >
<xsl:text
disable-output-escaping="yes"><![CDATA[<tr>]]></xsl:text>
</xsl:template>
</xsl:stylesheet>
EOT2
t/xml-grammar-failures.t view on Meta::CPAN
my $input_fn = File::Spec->catfile(
File::Spec->curdir(), "t", "data", "perl-begin-page.xml-grammar-vered.xml",
);
my $xslt_fn = File::Spec->catfile(
File::Spec->curdir(), "t", "data", "vered-xml-to-docbook.xslt",
);
my $source = XML::LibXML->load_xml(location => $input_fn);
my $style_doc = XML::LibXML->load_xml(location=>$xslt_fn, no_cdata=>1);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($source);
# TEST
like (scalar($stylesheet->output_as_bytes($results)),
qr/<db:listitem/,
"Rudimentary XSLT test just to make sure we reached here.",
);
( run in 0.642 second using v1.01-cache-2.11-cpan-454fe037f31 )