RE: [xsl] Recursively removing empty tags from deepest child upwards.

Subject: RE: [xsl] Recursively removing empty tags from deepest child upwards.
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Mon, 22 Mar 2004 15:30:32 -0000
>  I'm trying to remove certain empty tags from a set a files
> 
> e.g., simplified example
> 
> <?xml version="1.0" encoding="US-ASCII"?>
> <bdy>
>    <section><p>not empty</p><p></p></section>
>    <section><section><p></p></section></section>
> </bdy>
> 
> 
> I want
> 
> <?xml version="1.0" encoding="US-ASCII"?>
> <bdy>
>    <section><p>not empty</p></section>
> </bdy>
> 
> 
> i.e. in this example in the first section the empty <p></p> 
> is removed and the 
> whole of the second section removed since it contains just an 
> empty p and 
> empty section elements.

How about only copying a node through if it has a text() descendant:

<xsl:template match="@*|*">
  <xsl:copy>
    <xsl:apply-templates select="@*|*|text()"/>
  </xsl:copy>
</xsl:template>

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

Out of interest, can anyone with a knowledge of template matching
complexity tell me if this is O n^2 or if because it is within a match
pattern some other rule applies?

cheers
andrew

Current Thread