After searching for the node with the same name in other structure and replace his value, how can I duplicate the parent node of the matched one?
Can I set a key for each child's parent in the template?
From this,
<Message>
<XMLNSC>
<MaXML>
<Rule>
<A>RuleA</A>
<D>RuleD</D>
</Rule>
<Body>
<A>valA</A>
<B>valB</B>
<C>
<D>valD</D>
</C>
</Body>
</MaXML>
</XMLNSC>
To this,
<Message>
<XMLNSC>
<MaXML>
<Rule>
<A>RuleA</A>
<D>RuleD</D>
</Rule>
<Body>
<A>RuleA</A>
<A>RuleA</A>
<B>valB</B>
<C>
<D>RuleD</D>
<D>RuleD</D>
</C>
<C>
<D>RuleD</D>
<D>RuleD</D>
</C>
</Body>
<Body>
<A>RuleA</A>
<A>RuleA</A>
<B>valB</B>
<C>
<D>RuleD</D>
<D>RuleD</D>
</C>
<C>
<D>RuleD</D>
<D>RuleD</D>
</C>
</Body>
</MaXML>
</XMLNSC>
My XSLT, https://xsltfiddle.liberty-development.net/pPqsHTK/5
If you write a template for those descendants of
MaXML
which have a child element with a key match you can simply use the identity template twice on those descendant elements, I had the exclude theRule
elements explicitly then:https://xsltfiddle.liberty-development.net/pPqsHTK/6
With XSLT 3 it a bit easier:
https://xsltfiddle.liberty-development.net/pPqsHTK/8