From: sgunderson@bigfoot.com <> Date: Thu, 1 Mar 2007 14:19:55 +0000 (+0100) Subject: Revert r113 and r114, we'll try to solve it slightly differently. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=4153959f31e151e2629d4536e2183186f226e381;p=xml-template Revert r113 and r114, we'll try to solve it slightly differently. --- diff --git a/perl-sax/XML/TemplateSAX/Handler.pm b/perl-sax/XML/TemplateSAX/Handler.pm index b7917bc..3ec394b 100644 --- a/perl-sax/XML/TemplateSAX/Handler.pm +++ b/perl-sax/XML/TemplateSAX/Handler.pm @@ -23,11 +23,20 @@ sub new { sub start_element { my ($self, $data) = @_; my $obj = $self->{'obj'}; - + # find the ID, if any my $id = $data->{'Attributes'}->{'{http://template.sesse.net/}id'}; $id = $id->{'Value'} if (defined($id)); + # within a replacement; just ignore everything + return if (!defined($obj)); + + # within a cloning; slurp it up + if (ref($obj) eq 'XML::TemplateSAX::Buffer') { + $obj->start_element($data); + return; + } + # substitution: see if this element matches anything. if so, # descend down into the tree. if (ref($obj) eq 'HASH') { @@ -66,7 +75,8 @@ sub start_element { if (defined($match)) { $self->SUPER::start_element($data); - push @{$self->{'stack'}}, [ $data->{'Name'}, 0, $obj ]; + # FIXME: we should match on something better than the name. But what? + push @{$self->{'stack'}}, [ $data->{'Name'}, $obj ]; # # This is sort of ugly. We special-case replacement by outputting @@ -108,28 +118,6 @@ sub start_element { } } - # - # If we have multiple elements with the same name within each other, - # we need to keep track of how many there are, so check here and increment. - # end_element will decrement and optionally pop the stack. - # - my $stack = $self->{'stack'}; - if (scalar @$stack > 0) { - my $top = $stack->[scalar @$stack - 1]; - - if ($data->{'Name'} eq $top->[0]) { - ++$top->[1]; - } - } - - # within a replacement; just ignore everything - return if (!defined($obj)); - - # within a cloning; slurp it up - if (ref($obj) eq 'XML::TemplateSAX::Buffer') { - $obj->start_element($data); - return; - } $self->SUPER::start_element($data); } @@ -175,30 +163,26 @@ sub processing_instruction { sub end_element { my ($self, $data) = @_; - + my $stack = $self->{'stack'}; if (scalar @$stack > 0) { my $top = $stack->[scalar @$stack - 1]; if ($data->{'Name'} eq $top->[0]) { - if ($top->[1] == 0) { - my $obj = $self->{'obj'}; - - # did we just finish a clone operation? - if (ref($obj) eq 'XML::TemplateSAX::Buffer') { - for my $instance (@{$obj->{'ptr'}}) { - $self->{'obj'} = $instance; - $obj->replay($self); - } - } + my $obj = $self->{'obj'}; - $self->SUPER::end_element($data); - $self->{'obj'} = $top->[2]; - pop @$stack; - return; - } else { - --$top->[1]; + # did we just finish a clone operation? + if (ref($obj) eq 'XML::TemplateSAX::Buffer') { + for my $instance (@{$obj->{'ptr'}}) { + $self->{'obj'} = $instance; + $obj->replay($self); + } } + + $self->SUPER::end_element($data); + $self->{'obj'} = $top->[1]; + pop @$stack; + return; } }