|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: omitting empty elements when copying
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
|
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
|

Cart








