Subject:Strip Empty Element Trees Author:Ali Ebrahim Date:02 Apr 2007 07:40 PM
Hi,
We using the solution from Post "Strip Empty Elements and Attributes but leave Elements with populated attributes", but have noticed that it will only strip empty leaf elements. Our requirement is to strip the entire parent tree if ALL child branches to leaf elements does not hold data
Hope I have managed to explain our requirements. Are you able to assist with extending the above post's example code so that the entire tree is removed and not just the leaf element
eg.
<A>
<B>
<D>
<H>
</H>
</D>
</B>
<C>This is Blah1</C>
<E>
<F>
</F>
<G>This is Blah2</G>
</E>
</A>
So in the explample, after stripping the result needs to be
<A>
<C>This is Blah1</C>
<E>
<G>This is Blah2</G>
</E>
</A>
So, the entire tree from element <B> was stripped including children <D>, <H>. for Element <E> you can notice that only child element <F> has been stripped, since element <G> has data.
Subject:Strip Empty Element Trees Author:Ali Ebrahim Date:03 Apr 2007 10:25 PM
Ivan,
Thanx for the sample xsl....
I have tested the code and noticed that the code did not copy any attributes across for those parent elements who's leaf elements have values.
So using the example xml:
=========================
<A>
<B Id="">
<D id="">
<H>
</H>
</D>
</B>
<C id="1213">This is Blah1</C>
<E Id="">
<F>
</F>
<G id="">This is Blah2</G>
</E>
</A>
The result should be:
=====================
<A>
<C id="1213">This is Blah1</C>
<E Id="">
<G id="">This is Blah2</G>
</E>
</A>
Are you able to change CopyTree.xsl to accomodate the above result?