This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Empty elements
- From: Ingo Schildmann <Ingo dot Schildmann at WiredMinds dot de>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 22 Feb 2002 16:48:03 +0100
- Subject: Re: [xsl] Empty elements
- Organization: WiredMinds Informationssysteme GmbH
- References: <3FCBADF3E5B4D111B62E0001FAF82EAA02AB56B1@NMUKEXS1>
- Reply-to: xsl-list at lists dot mulberrytech dot com
On Thursday 21 February 2002 18:47, you wrote:
> I've got a document that looks similar to below:
>
> <message_wrapper>
> <msg_header>
> <token>a token</token>
> <language>a language</language>
> </msg_header
> <msg_body>
> <group>
> <element1>value 1</element1>
> <element2>value 2</element2>
> </group>
> <group>
> <element1>value 3</element1>
> <element2>value 4</element2>
> </group>
> <group>
> <element1></element1>
> <element2></element2>
> </group>
> <group>
> <element1></element1>
> <element2></element2>
> </group>
> </msg_body>
> </message_wrapper>
>
> How can I remove the empty groups ?
> message_wrapper & msg_body will always have the same names, but the names
> of the group & element* elements will not always be the same.
The whitespace in the groups may be problematic. As long as a group is
considered empty if the value of all elements is only whitespace, too,
you could try this:
use the generic copy template:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
and add a template which matchs the elements whose stringvalue is only
whitespace and does nothing.
<xsl:template match="*[not(normalize-space())]" />
--
Ingo Schildmann
Development
WiredMinds Informationssysteme GmbH
email: Ingo.Schildmann@WiredMinds.de
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list