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

Re: omitting empty elements when copying

Subject: Re: omitting empty elements when copying
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 5 Feb 2003 12:53:26 +0000
xsl filter empty tags
Hi Jan,

> I want to copy only the elements with content

Whenever you want to copy-with-amendments, your best starting point is
the identity template, which performs a deep copy by recursing down
the tree:

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

Then you can add templates that match the things that you want to
remove from the tree and do nothing with them. In your case, a
template that matches the empty elements:

<xsl:template match="*[not(node())]" />

Note that "empty" means different things to different people. The
above will filter out elements that are truly empty, but won't filter
out elements that contain only comments, processing-instructions or
whitespace-only text. It also won't filter out elements that only
contain other elements that are empty. So you might want:

<xsl:template match="*[not(normalize-space())]" />

instead, which will filter out all elements that don't contain any
textual content.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread

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.