How to add a new element to every child element of a certain parent? For example, consider you want to add <type> element to the element under <library>. The <type> element should have the name of the element as the value. The resultant XML should look like this. The following XSLT does the trick.