--- nfo/perl/libs/XML/XSLT.pm 2003/04/26 01:44:00 1.1 +++ nfo/perl/libs/XML/XSLT.pm 2003/04/30 00:06:55 1.2 @@ -6,8 +6,8 @@ # and Egon Willighagen, egonw@sci.kun.nl # # $Log: XSLT.pm,v $ -# Revision 1.1 2003/04/26 01:44:00 joko -# initial commit - from http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/xmlxslt/XML-XSLT/lib/XML/XSLT.pm?rev=1.19&content-type=text/vnd.viewcvs-markup +# Revision 1.2 2003/04/30 00:06:55 joko +# NEW: sub __evaluate_test__ now detects a variable name in an lvalue of an expression (e.g. $var=val, {$var}=val) # # Revision 1.19 2002/02/18 09:05:14 gellyfish # Refactoring @@ -496,7 +496,7 @@ foreach my $child ($xsl->getElementsByTagName ('*', 0)) { - my ($ns, $tag) = split(':', $child->getTagName()); + my ($ns, $tag) = split(':', $child->getTagName()); if(not defined $tag) { $tag = $ns; @@ -2605,8 +2605,53 @@ $self->debug("no test matches"); return 0; } + + # tests for variables|parameters + } elsif ($test =~ /^\s*{*\$([\w\.\:\-]+)}*\s*(<=|>=|!=|=|<|>)\s*['"]?([^'"]*)['"]?\s*$/) { + my $expval = $3; + my $test = $2; +=pod + my $nodeset=&_get_node_set($self,$1,$self->xml_document(),$path,$node,$variables); + return ($expval ne '') unless @$nodeset; + my $content = &__string__($self,$$nodeset[0]); +=cut + my $variable_name = $1; + my $content = &__string__($self,$variables->{$variable_name}); + my $numeric = $content =~ /^\d+$/ && $expval =~ /^\d+$/ ? 1 : 0; + + $self->debug("evaluating $content $test $expval"); + + if ( $test eq '!=' ) + { + return $numeric ? $content != $expval : $content ne $expval; + } + elsif ( $test eq '=' ) + { + return $numeric ? $content == $expval : $content eq $expval; + } + elsif ( $test eq '<' ) + { + return $numeric ? $content < $expval : $content lt $expval; + } + elsif ( $test eq '>' ) + { + return $numeric ? $content > $expval : $content gt $expval; + } + elsif ( $test eq '>=' ) + { + return $numeric ? $content >= $expval : $content ge $expval; + } + elsif ( $test eq '<=' ) + { + return $numeric ? $content <= $expval : $content le $expval; + } + else + { + $self->warn("no test matches while evaluating parameter comparison: $test"); + return 0; + } } else { - $self->debug("no match for test"); + $self->debug("no match for test"); return ""; } }