[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: [XSLT 1.0] Q: recursively eliminate empty nodes

Subject: Re: [XSLT 1.0] Q: recursively eliminate empty nodes
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 08 Nov 2010 18:55:33 +0000
Re:  [XSLT 1.0] Q: recursively eliminate empty nodes
On 08/11/2010 18:22, Hermann Stamm-Wilbrandt wrote:

Hello,


I was given an identity transformation that eliminates empty nodes.
   <!-- identity template -->
   <xsl:template match="@*|node()">
     <xsl:copy>
       <xsl:apply-templates select="@*|node()" />
     </xsl:copy>
   </xsl:template>
   <xsl:template match="*[not(node())]" />

I was asked on how to do this until all empty nodes are gone, even the
newly created empty nodes after removal of an inner empty node.
The question was on whether this can be done without applying the
stylesheet again and again.

I came up with below (working) "XSLT 1.0 + exslt:node-set()" solution.

The question is, whether this can be done with pure XSLT 1.0?
Especially I want to know whether it can be done without node-set()
function -- just to make sure that not every problem looks like a
nail given the exslt:node-set() hammer ...


it depends if this is all the stylesheet is doing or if there are other templates processing other nodes. In the latter case you probably have to two two passes, with :node-set but if it really is an identity template plus strip empty nodes then really you are stripping any nodes with text node descendants so (assuming you use xsl:strip-space elements="*" to get rid of indentation you can just use


<xsl:template match="*[not(.//text())]" />

or


<xsl:template match="*[not(normalize-space())]" />



David


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.