XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Ali EbrahimSubject: 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.

Regards,
Ali

Postnext
Ivan PedruzziSubject: Strip Empty Element Trees
Author: Ivan Pedruzzi
Date: 02 Apr 2007 10:41 PM

Ali,

In order to get support from this forum you need to provide the Stylus Studio edition and build number?

Ivan Pedruzzi
Stylus Studio Team

Postnext
Ali EbrahimSubject: Strip Empty Element Trees
Author: Ali Ebrahim
Date: 03 Apr 2007 04:44 AM
Ivan,

Enterprize Suite, Build 735f

Registered to ORIGIN Energy Australia


Regards,
Ali

Postnext
Ivan PedruzziSubject: Strip Empty Element Trees
Author: Ivan Pedruzzi
Date: 03 Apr 2007 07:58 AM

The attached solution copies all branches ending with leafs with values that more then ignorable white-spaces.

It is a variation of the basic identity transform that probes the sub-tree before recurring.


Ivan Pedruzzi
Stylus Studio Team


DocumentCopyTree.xsl

Postnext
Ali EbrahimSubject: 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?


Many Thanx
Ali

Postnext
Ivan PedruzziSubject: Strip Empty Element Trees
Author: Ivan Pedruzzi
Date: 03 Apr 2007 10:50 PM

change

<xsl:copy-of select="@*[string-length(normalize-space())]"/>

to

<xsl:copy-of select="@*"/>

Ivan

Posttop
Ali EbrahimSubject: Strip Empty Element Trees
Author: Ali Ebrahim
Date: 04 Apr 2007 12:27 AM
Thanx a stack Ivan for your assistance and quick turn around. The code now meets all our requirements.

Regards,
Ali

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.