use strict;
use warnings;
use Test::More tests => 5; # last test to print
use XML::XPathScript;
my $xps = XML::XPathScript->new();
$xps->set_xml( 'onezwei'
.'trois' );
$xps->set_stylesheet( <<'END_STYLESHEET' );
<%
$template->set( foo => { content => '<{@type}><%~ bar %>{@type}>' } );
%>
<%-~ /doc -%>
END_STYLESHEET
is $xps->transform => 'zwei';
$xps->set_xml( <<'END_XML' );
END_XML
$xps->set_stylesheet( <<'END_STYLESHEET' );
<%-
$template->set( track => { content => <<'END_CONTENT' } );
<%-# will turn
into
Weird Al Yankovic
lyrics available
-%>
<%-~ artist -%>
<% if ( findnodes( 'lyrics' ) ) { -%>
lyrics available
<%- } -%><%- -%>
END_CONTENT
-%>
<%-~ //track -%>
END_STYLESHEET
is $xps->transform => 'Weird Al Yankoviclyrics available';
$xps->set_xml( '' );
$xps->interpolation( 0 );
$xps->set_stylesheet( <<'END_STYLESHEET' );
<%- $template->set( foo => { content => '<%= $params{myattr} %>' } );
-%><%= apply_templates( '//foo' => { myattr => 'bar' } ) -%>
END_STYLESHEET
is $xps->transform => 'bar';
# messing with $self shouldn't mess up with the processor
$xps->set_stylesheet( <<'END_STYLESHEET' );
<%- $template->set( foo => { content => '<%= $self = "mouahaha" %>' } );
-%><%= apply_templates( '//foo' ) -%>
END_STYLESHEET
is $xps->transform => 'mouahaha';
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
my $stylesheet = <<'END_STYLESHEET';
<%@ track
<%~ title %>
<%~ lyrics %>
-%>
<%-@ title
{text()}
-%>
<%-~ / -%>
END_STYLESHEET
$xps->interpolation(1);
$xps->set_stylesheet( $stylesheet );
$xps->set_xml( <<'END_XML' );
END_XML
my $result = $xps->transform;
$result =~ s/\s+/ /g;
is $result => ' White and Nerdy
... Forever and One
'
.' ... ';