title: Modifying an xml attribute element with a value of a child element with lxml
body: <p>I have an XML snippet like this:</p>
  
  <pre><code>&lt;parent id="1"&gt;
      &lt;child1&gt;
          &lt;child2&gt;[content]I need to get[/content]Other text&lt;/child2&gt;
      &lt;/child1&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>And I would like to add the [content] of "child1" as an attribute into the parent element.</p>
  
  <p>Getting something like this:</p>
  
  <pre><code>&lt;parent id="1" value = "I need to get"&gt;
      &lt;child1&gt;
          &lt;child2&gt;Other text&lt;/child2&gt;
      &lt;/child1&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>I have this code, however it does not work as it looks like it only iters in the first child and does not go to the next.</p>
  
  <pre><code>pattern = re.compile('[content](.*?)[/content]')
  xml_parser = et.parse(str(xml_file))
  root_xml = xml_parser.getroot()
  translatable_elements = root_xml.xpath('//parent')
  for element in translatable_elements:
      for child_element in element.iterchildren():
          if child_element.tag == 'child1':
              source_content = child_element.text
              value_str = pattern.match(source_content).group(1)
              element.attrib['value'] = value_str
              source_content = pattern.sub(source_content,'')
      tree = et.ElementTree(root_xml)
   tree.write(str(xml_file), encoding='utf-8', pretty_print=True)
  </code></pre>