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


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


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