How do we filter an xml document based on another xml document. I have to remove all the elements which are not there in the lookup xml. Both the input xml and lookup xml has the same root elements, we are using XSLT 1.0.
Ex Input
<Root>
<E1 a="1">V1</E1>
<E2>V2</E2>
<E3>V3</E3>
<E5>
<SE51>SEV1</SE51>
<SE52>SEV2</SE52>
</E5>
<E6>
<SE61>SEV3</SE61>
<SE62>SEV4</SE62>
</E6>
</Root>
Filter Xml
<Root>
<E1 a="1"></E1>
<E2></E2>
<E5>
<SE51></SE51>
<SE52></SE52>
</E5>
</Root>
Expected Output
<Root>
<E1 a="1">V1</E1>
<E2>V2</E2>
<E5>
<SE51>SEv1</SE51>
<SE52>SEV2</SE52>
</E5>
</Root>
Here is the required transformation:
When this transformation is applied on the following XML document (the original one plus the addition of
<SE511>SEV11</SE511>
to demonstrate that the filtering works on any level:the wanted result is produced:
Do notice the following details of this solution:
Do enjoy!
Based on what I've done in the past when faced with similar problems I'd suggest:
It sounds (and is) ugly, but I've found this easier than trying to interpret the filter description on the fly while transforming the input.
Hmmm, you're sort of talking about merging (assuming your filter doc is variable). There's a couple of possibilities which vary with the language you're implementing all of this in. Could you provide more info about the app?
Otherwise I suggest a quick google on "xslt +merge" and see if some result there grabs you.