Re: [xsl] How to strip off all empty elements from a XML doc?

Subject: Re: [xsl] How to strip off all empty elements from a XML doc?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 07 Oct 2009 09:40:57 -0400
At 2009-10-07 15:39 +0200, Ben Stover wrote:
Just another question:

Assume a XML doc contains (sub)elements with no content like


How can I strip off/delete recursively ALL these empty elements
from the XML element tree (but keep all others)?

Add to a stylesheet with the identity template a template that adds nothing to the result tree for elements with no content:

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

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

I hope this helps.

. . . . . . . . . . Ken

Upcoming: hands-on code list, UBL, XSLT, XQuery and XSL-FO classes
in Copenhagen Denmark and Washington DC USA, October/November 2009
Interested in other classes?
Crane Softwrights Ltd.
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:
Video overview:
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread