Beispiel #1
0
 def instantiate(self, context):
     context.namespaces = self.namespaces
     targets = self.select.evaluate_as_nodeset(context)
     if not targets:
         raise XUpdateError(XUpdateError.INVALID_SELECT)
     for target in targets:
         context.push_tree_writer(target.xml_base)
         for primitive in self:
             primitive.instantiate(context)
         writer = context.pop_writer()
         tr = writer.get_result()
         if self.child:
             focus = context.node, context.position, context.size
             try:
                 context.node = target
                 context.position = 1
                 size = context.size = len(target.xml_children)
                 position = int(self.child.evaluate_as_number(context))
             finally:
                 context.node, context.position, context.size = focus
             if position < size:
                 refnode = target.xml_children[position]
             else:
                 refnode = None
         else:
             refnode = None
         while tr.xml_first_child:
             if refnode is not None:
                 offset = target.xml_index(refnode)
                 target.xml_insert(offset, tr.xml_first_child)
             else:
                 target.xml_append(tr.xml_first_child)
     return
Beispiel #2
0
 def instantiate(self, context):
     context.namespaces = self.namespaces
     targets = self.select.evaluate_as_nodeset(context)
     if not targets:
         raise XUpdateError(XUpdateError.INVALID_SELECT)
     for target in targets:
         if target.xml_type == tree.element.xml_type:
             context.push_tree_writer(target.xml_base)
             for primitive in self:
                 primitive.instantiate(context)
             writer = context.pop_writer()
             tr = writer.get_result()
             while target.xml_first_child:
                 target.xml_remove(target.xml_first_child)
             while tr.xml_first_child:
                 target.xml_append(tr.xml_first_child)
         elif target.xml_type in (tree.attribute.xml_type,
                                  tree.text.xml_type,
                                  tree.comment.xml_type,
                                  tree.processing_instruction.xml_type):
             context.push_string_writer(errors=False)
             for primitive in self:
                 primitive.instantiate(context)
             writer = context.pop_writer()
             value = writer.get_result()
             if not value and target.xml_type == tree.text.xml_type:
                 target.xml_parent.xml_remove(target)
             else:
                 target.xml_value = value
     return
Beispiel #3
0
 def instantiate(self, context):
     context.namespaces = self.namespaces
     for target in self.select.evaluate_as_nodeset(context):
         context.push_tree_writer(target.xml_base)
         for primitive in self:
             primitive.instantiate(context)
         writer = context.pop_writer()
         tr = writer.get_result()
         parent = target.xml_parent
         while tr.xml_first_child:
             offset = parent.xml_index(target)
             parent.xml_insert(offset, tr.xml_first_child)
     return
Beispiel #4
0
 def instantiate(self, context):
     context.namespaces = self.namespaces
     for target in self.select.evaluate_as_nodeset(context):
         context.push_tree_writer(target.xml_base)
         for primitive in self:
             primitive.instantiate(context)
         writer = context.pop_writer()
         tree = writer.get_result()
         parent = target.xml_parent
         target = target.xml_following_sibling
         while tree.xml_first_child:
             if target is not None:
                 offset = parent.xml_index(target)
                 parent.xml_insert(offset, tree.xml_first_child)
             else:
                 parent.xml_append(tree.xml_first_child)
     return