]> git.sesse.net Git - xml-template/commitdiff
Try to fix the structure test, but fail miserably.
authorsgunderson@bigfoot.com <>
Thu, 1 Mar 2007 13:49:25 +0000 (14:49 +0100)
committersgunderson@bigfoot.com <>
Thu, 1 Mar 2007 13:49:25 +0000 (14:49 +0100)
perl-sax/XML/TemplateSAX/Handler.pm

index 3ec394b86b45f95e3da86abd931b8d161300c6c0..72a506c36db51d6596b55f5ecac3be88c677e321 100644 (file)
@@ -28,6 +28,20 @@ sub start_element {
        my $id = $data->{'Attributes'}->{'{http://template.sesse.net/}id'};
        $id = $id->{'Value'} if (defined($id));
 
+       # 
+       # 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));
 
@@ -75,8 +89,7 @@ sub start_element {
                if (defined($match)) {
                        $self->SUPER::start_element($data);
                
-                       # FIXME: we should match on something better than the name. But what?
-                       push @{$self->{'stack'}}, [ $data->{'Name'}, $obj ];
+                       push @{$self->{'stack'}}, [ $data->{'Name'}, 0, $obj ];
 
                        #
                        # This is sort of ugly. We special-case replacement by outputting
@@ -169,20 +182,24 @@ sub end_element {
                my $top = $stack->[scalar @$stack - 1];
                
                if ($data->{'Name'} eq $top->[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);
+                       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);
+                                       }
                                }
-                       }
 
-                       $self->SUPER::end_element($data);
-                       $self->{'obj'} = $top->[1];
-                       pop @$stack;
-                       return;
+                               $self->SUPER::end_element($data);
+                               $self->{'obj'} = $top->[2];
+                               pop @$stack;
+                               return;
+                       } else {
+                               --$top->[1];
+                       }
                }
        }