[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|