<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># $Id: LocationPath.pm,v 1.8 2001/03/16 11:10:08 matt Exp $

package XML::XPathEngine::LocationPath;
use XML::XPathEngine::Root;
use strict;

sub new {
	my $class = shift;
	my $self = [];
	bless $self, $class;
}

sub as_string {
	my $self = shift;
	my $string;
	for (my $i = 0; $i &lt; @$self; $i++) {
		$string .= $self-&gt;[$i]-&gt;as_string;
		$string .= "/" if $self-&gt;[$i+1];
	}
	return $string;
}

sub as_xml {
    my $self = shift;
    my $string = "&lt;LocationPath&gt;\n";
    
    for (my $i = 0; $i &lt; @$self; $i++) {
        $string .= $self-&gt;[$i]-&gt;as_xml;
    }
    
    $string .= "&lt;/LocationPath&gt;\n";
    return $string;
}

sub set_root {
	my $self = shift;
	unshift @$self, XML::XPathEngine::Root-&gt;new();
}

sub evaluate {
	my $self = shift;
	# context _MUST_ be a single node
	my $context = shift;
	die "No context" unless $context;
	
	# I _think_ this is how it should work :)
	
	my $nodeset = XML::XPathEngine::NodeSet-&gt;new();
	$nodeset-&gt;push($context);
	
	foreach my $step (@$self) {
		# For each step
		# evaluate the step with the nodeset
		my $pos = 1;
		$nodeset = $step-&gt;evaluate($nodeset);
	}
	
	return $nodeset;
}

1;
</pre></body></html>