Browse files

Fix replace logic if element to replace is root

  • Loading branch information...
1 parent d2c6633 commit f0f97501a330646565ad7402c305256877200cac @tomill committed Feb 14, 2010
Showing with 19 additions and 2 deletions.
  1. +7 −2 lib/Template/Semantic/Document.pm
  2. +12 −0 t/05_value-type.t
View
9 lib/Template/Semantic/Document.pm
@@ -146,7 +146,12 @@ sub _assign_value {
my $parted = $self->_to_node($node->serialize);
$self->_query($parted, $value);
- $node->replaceNode($parted);
+
+ if ($node->isSameNode( $self->{dom}->documentElement )) { # to replace root
+ $self->{dom}->setDocumentElement($parted);
+ } else {
+ $node->replaceNode($parted);
+ }
}
}
@@ -374,7 +379,7 @@ Gets the result as L<XML::LibXML::Document>.
=head1 SEE ALSO
-L<Template::Semantic>
+L<Template::Semantic>, L<XML::LibXML::Document>
=head1 AUTHOR
View
12 t/05_value-type.t
@@ -225,6 +225,18 @@ use XML::LibXML;
<a href="zzz" class="yyy">xxx</a>
</root>
+=== elem (root) x hashref
+--- note: test for "replaceChild: HIERARCHY_REQUEST_ERR"
+--- vars
+'/root' => {
+ '.' => 'xxx',
+ './@class' => 'yyy',
+}
+--- template
+<root class="foo"></root>
+--- expected
+<root class="yyy">xxx</root>
+
=== elem x list (xpath)
--- vars
'ul.list li' => [

0 comments on commit f0f9750

Please sign in to comment.