[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Empty elements

Subject: Re: Empty elements
From: Ingo Schildmann <Ingo.Schildmann@xxxxxxxxxxxxx>
Date: Fri, 22 Feb 2002 16:48:03 +0100
Re:  Empty elements
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@xxxxxxxxxxxxx  


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • Re: Empty elements, (continued)
    • TP - Thu, 21 Feb 2002 13:24:37 -0500 (EST)
      • Michael Kay - Thu, 21 Feb 2002 13:46:31 -0500 (EST)
      • TP - Thu, 21 Feb 2002 13:50:19 -0500 (EST)
    • Ingo Schildmann - Fri, 22 Feb 2002 10:45:21 -0500 (EST) <=

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.