Remove all child nodes except last using XSLT



I have an XML file as such:



<a>
<b>
<e/ >
<f/ >
</b>
<c>
<g>
<j/ >
</g>
<g>
<j/ >
</g>
<g>
<j/ >
</g>
</c>
<d>
<h>
<i/ >
</h>
<h>
<i/ >
</h>
<h>
<i/ >
</h>
</d>
</a>


What I'm trying to do is to apply an XSLT transformation to get only get the last nodes of c and d (including their child nodes), resulting in:



<a>
<b>
<e/ >
<f/ >
</b>
<c>
<g>
<j/ >
</g>
</c>
<d>
<h>
<i/ >
</h>
</d>
</a>


I am not experienced with XSLT and any help is greatly appreciated.


No comments:

Post a Comment