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

RE: empty elements

Subject: RE: empty elements
From: "DuCharme, Bob (LNG)" <bob.ducharme@xxxxxxxxxxxxxx>
Date: Tue, 4 Dec 2001 15:49:37 -0500
xalan empty element
Polini Mirco wrote:

>I must delete my xml input from empty elements; i'm using xalan processor
>How can I control, in the stylesheet, if an element is empty.

If I understand you correctly, you want to check whether an element is empty
and not copy it to the result tree if so, right? 

Something like this will do it:

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		 version="1.0">

	 <xsl:template match="*">
		<xsl:if test="normalize-space(.)">
		<xsl:copy>
		  <xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
		</xsl:if>

	 </xsl:template>

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


  </xsl:stylesheet>

The first template rule checks whether, after getting rid of extraneous
white space, an element has anything left. If so, it gets copied. (The other
template rule copies the attributes.)

There's more about this in section 3.10 of my book. 

Bob DuCharme            www.snee.com/bob         <bob@  
snee.com>  see http://www.snee.com/bob/xsltquickly for
info on book "XSLT Quickly" from Manning Publications.

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


Current Thread
  • empty elements
    • Polini Mirco - Tue, 4 Dec 2001 09:54:57 -0500 (EST)
      • <Possible follow-ups>
      • DuCharme, Bob (LNG) - Tue, 4 Dec 2001 15:50:27 -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.