[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: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 08 Nov 2010 14:03:56 -0500
Re:  [XSLT 1.0] Q: recursively eliminate empty nodes
At 2010-11-08 19:22 +0100, Hermann Stamm-Wilbrandt wrote:
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.
...
$ cat x.xml
<a><b>c<c/></b><b><c/></b></a>

Are you defining, then, an "ultimately" empty node as being a node that doesn't have descendent text nodes?


If not, then please clarify with more examples. The code below gives you what your recursive solution gives you, but I can't tell from your specification if that is what you really want.

Perhaps you are simply looking too deep at the problem?

I hope this helps.

. . . . . . . . . Ken

~/t/ftemp $ cat hermann.xml
<a><b>c<c/></b><b><c/></b></a>
~/t/ftemp $ xslt hermann.xml hermann.xsl
<?xml version="1.0" encoding="utf-8"?><a><b>c</b></a>
~/t/ftemp $ cat hermann.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

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

<xsl:template match="@*|node()"><!--identity for all other nodes-->
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
~/t/ftemp $



--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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.