summaryrefslogtreecommitdiff
path: root/t/06-libxml.t
blob: 237773870a343bc457cd17c10e790e8243767ace (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!perl 
package XmlTransform;{ 
 use Tree::Transform::XSLTish;
 use strict;
 use warnings;
 
 default_rules;
 
 tree_rule match => 'img[@alt="pick"]'action => sub {
     return $_[0]->it->findvalue('@src');
 };
 
}
 
package main; 
use Test::Most 'die';
use strict;
use warnings;
eval 'use XML::LibXML;use XML::LibXML::XPathContext;';
plan skip_all => 'XML::LibXML and XML::LibXML::XPathContext needed for this test' if $@;
plan tests=>1;
 
my $tree=XML::LibXML->new->parse_string(<<'XML');
<html>
 <body>
  <p>test</p>
  <img src="nothing" />
  <img src="this one" alt="pick" />
 </body>
</html>
XML
 
{
my $trans=XmlTransform->new(engine=>XML::LibXML::XPathContext->new());
my @results=$trans->transform($tree);
is_deeply \@results,['this one'],'XML example';
}