diff options
author | Gianni Ceccarelli <dakkar@dechirico.(none)> | 2009-03-27 15:55:27 +0100 |
---|---|---|
committer | Gianni Ceccarelli <dakkar@dechirico.(none)> | 2009-03-27 15:55:27 +0100 |
commit | 0940c294d02b0750e03ec551273de1d874fdf09b (patch) | |
tree | a10da2f520788166d0a578ddcf311ff529d2b696 /t/06-libxml.t | |
parent | added prereq (diff) | |
download | Tree-Transform-XSLTish-0940c294d02b0750e03ec551273de1d874fdf09b.tar.gz Tree-Transform-XSLTish-0940c294d02b0750e03ec551273de1d874fdf09b.tar.bz2 Tree-Transform-XSLTish-0940c294d02b0750e03ec551273de1d874fdf09b.zip |
testing engine_factory and XML namespace support
Diffstat (limited to 't/06-libxml.t')
-rw-r--r-- | t/06-libxml.t | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/t/06-libxml.t b/t/06-libxml.t index f496301..94f1ae8 100644 --- a/t/06-libxml.t +++ b/t/06-libxml.t @@ -1,4 +1,11 @@ #!perl +package main; +use Test::Most 'die'; +BEGIN { + eval 'use XML::LibXML;use XML::LibXML::XPathContext;'; + plan skip_all => 'XML::LibXML and XML::LibXML::XPathContext needed for this test' if $@; +} + package XmlTransform;{ use Tree::Transform::XSLTish ':engine'; use strict; @@ -14,14 +21,32 @@ package XmlTransform;{ } +package NSXmlTransform;{ + use Tree::Transform::XSLTish ':engine'; + use XML::LibXML::XPathContext; + use strict; + use warnings; + + engine_factory { + my $e=XML::LibXML::XPathContext->new(); + $e->registerNs('t','http://test/'); + return $e; + }; + + default_rules; + + tree_rule match => 't: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; +plan tests=>2; +{ my $tree=XML::LibXML->new->parse_string(<<'XML'); <html> <body> @@ -32,8 +57,24 @@ my $tree=XML::LibXML->new->parse_string(<<'XML'); </html> XML -{ my $trans=XmlTransform->new(); my @results=$trans->transform($tree); is_deeply \@results,['this one'],'XML example'; } + +{ +my $tree=XML::LibXML->new->parse_string(<<'XML'); +<html xmlns:x="http://test/"> + <body> + <p>test</p> + <img src="nothing" /> + <img src="this one" alt="pick" /> + <x:img src="this one" alt="pick" /> + </body> +</html> +XML + +my $trans=NSXmlTransform->new(); +my @results=$trans->transform($tree); +is_deeply \@results,['this one'],'XML namespaces'; +} |