xsl-list
[Top] [All Lists]

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

2009-10-15 05:42:29
Hello Martin,

your solution does not cover nested (!) empty elements. Lets think of the 
following XML chunk:

  <xsl:output indent="yes"/>
...
<aaa>
   <bbb></bbb>
   <ccc/>
</aaa>

Your script will result in:

<aaa>


</aaa>

...removing only "inner" empty elements. How can I recursively delete "upper" 
empty elements as well (even if the become empty during the processing)?

By the way: Your template replace the empty elements by (two) blank lines. How 
can I tell the XSLT proc to 
remove the blank lines as well?

Ben

On Wed, 07 Oct 2009 15:41:52 +0200, Martin Honnen wrote:

Ben Stover wrote:
Just another question:

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

<myelem22></myelem22>
or
<myelem22/>

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

Two template do that:

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

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
-- 
      Martin Honnen
      http://msmvps.com/blogs/martin_honnen/
















--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--