# ansible xml; setting child element based on node attribute value

**URL:** <https://forum.ansible.com/t/ansible-xml-setting-child-element-based-on-node-attribute-value/27756>\
**Category:** Ansible Project\
**Created:** [June 9, 2018, 12:44pm UTC](https://forum.ansible.com/t/ansible-xml-setting-child-element-based-on-node-attribute-value/27756 "2018-06-09T12:44:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali\_Khawaja](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Ali\_Khawaja](https://forum.ansible.com/u/Ali_Khawaja)\
**Post date:** [June 9, 2018, 12:44pm UTC](https://forum.ansible.com/t/ansible-xml-setting-child-element-based-on-node-attribute-value/27756/1 "2018-06-09T12:44:59Z")

</div>

Hi,

i have multiple xml node which multiple child elements. each node differs from other based on the value of its attribute.

i want to set the value of child elements based on the value of the parent node’s attribute. when i try to select the node based on the attribute value and then its children value, it says that the two operations are mutually exclusive.

[https://pastebin.com/6jv7pgGN](https://pastebin.com/6jv7pgGN)

do i need to break the operation into two separate operations? is it possible to accomplish this in a single xml task?

Regards  
Ali

---

<div class="post-metadata">

**Author:** ![Ali\_Khawaja](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Ali\_Khawaja](https://forum.ansible.com/u/Ali_Khawaja)\
**Post date:** [June 9, 2018, 2:59pm UTC](https://forum.ansible.com/t/ansible-xml-setting-child-element-based-on-node-attribute-value/27756/2 "2018-06-09T14:59:35Z")

</div>

i was able to figure out this one by using xpath expression, but a new problem is that when you do set\_children on any one of its child, it wipes out all the other child elements, which seems to be the behavior by design, which seems to be a very strange behavior compared to all other tools that do xml manipulation.

is there a way that i can set the value of a child elements and preserve all my other child nodes?

Regards  
Ali
