This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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@WiredMinds.de  


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]