Move XML element using XDT

282 views Asked by At

Is there a way to move an XML element, including all of its content, inside another element using XDT?

For example, I'd like to transform the following XML:

<?xml version="1.0"?>
<a>
    <b someAttribute="someValue">someContent</b>
</a>

into this:

<?xml version="1.0"?>
<a>
    <c>
        <b someAttribute="someValue">someContent</b>
    </c>
</a>

by moving the b element inside of the newly created c element. I was hoping that something like the following would work:

<?xml version="1.0"?>
<a xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <c xdt:Transform="Insert">
        <b xdt:Locator="XPath(/a/b)" xdt:Transform="an appropriate transform" />
    </c>
</a>

But AFAIK there is no transform that would do this.

1

There are 1 answers

0
Rogier van het Schip On BEST ANSWER

This is currently not supported, as answered in Web.config transforms - surrounding elements, but this question does offer one workaround.