]> git.sesse.net Git - xml-template/commitdiff
Fix the namespace handling in the Perl variant.
authorsgunderson@bigfoot.com <>
Sat, 12 Aug 2006 19:25:23 +0000 (21:25 +0200)
committersgunderson@bigfoot.com <>
Sat, 12 Aug 2006 19:25:23 +0000 (21:25 +0200)
perl/XML/Template.pm

index c148eccf19a8db47e422565a1d4df7ba663ab860..ed44d63ddeb5abab7989f38bbe5734ce1b05fe27 100644 (file)
@@ -23,21 +23,7 @@ sub process {
        if (!defined($nsup)) {
                $nsup = XML::NamespaceSupport->new;
        }
-       $nsup->push_context;
-
-       # see if this node contains any namespace declarations that are relevant
-       # for us
-       my $attrs = $node->getAttributes;
-       if (defined($attrs)) {
-               for my $attr ($attrs->getValues) {
-                       my $name = $attr->getName;
-                       if ($name =~ /^xmlns:(.*)$/) {
-                               $nsup->declare_prefix($1, $attr->getValue);
-                               $node->removeAttribute($name) if ($clean);
-                       }
-               }
-       }
-       
+
        if (!ref($obj)) {                                                       # overwrite
                for my $child ($node->getChildNodes) {
                        $node->removeChild($child);
@@ -62,8 +48,23 @@ sub process {
        } elsif (ref($obj) eq 'HASH') {                                         # substitute
                for my $child ($node->getChildNodes) {
                        my $processed = 0;
+                       $nsup->push_context;
 
                        if ($child->getNodeType == XML::DOM::ELEMENT_NODE) {
+                               # see if this node contains any namespace declarations that are relevant
+                               # for us
+                               my $attrs = $child->getAttributes;
+                               if (defined($attrs)) {
+                                       for my $attr ($attrs->getValues) {
+                                               my $name = $attr->getName;
+                                               if ($name =~ /^xmlns:(.*)$/) {
+                                                       $nsup->declare_prefix($1, $attr->getValue);
+                                                       $child->removeAttribute($name) if ($clean);
+                                               }
+                                       }
+                               }
+                               print $child->getTagName, "\n";
+
                                my (undef, undef, $tag) = $nsup->process_element_name($child->getTagName);
 
                                my $id;
@@ -97,6 +98,7 @@ sub process {
                        }
 
                        process($child, $obj, $clean, $nsup) unless ($processed);
+                       $nsup->pop_context;
                }
        } elsif (ref($obj) eq 'ARRAY') {                                        # repeat
                my $doc = $node->getOwnerDocument;
@@ -118,12 +120,10 @@ sub process {
                }
 
                $frag->dispose;
-               $nsup->pop_context;
                return;
        }
 
        clean($node, $nsup) if $clean;
-       $nsup->pop_context;
 }
 
 sub clean {