This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Only copy nodes that have text at some point in the tree
- To: mjyoungblut at mmm dot com
- Subject: [xsl] Re: Only copy nodes that have text at some point in the tree
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- Date: Sat, 29 Sep 2001 08:14:41 -0700 (PDT)
- Cc: xsl-list at lists dot mulberrytech dot com
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Matt,
Here's a very short and simple solution to your problem.
It copies only those nodes that are text or have descendants-text:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()[descendant-or-self::text()]|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
It transforms your source xml file to:
<Catalog>
<Product NodeID="B" Action="A">
<Child>
<Grandchild>Steven</Grandchild>
</Child>
</Product>
<Product NodeID="C" Action="A">
<Child>
<Grandchild>Paul</Grandchild>
</Child>
</Product>
</Catalog>
Hope this helped.
Cheers,
Dimitre Novatchev.
------------------------------------------------------
mjyoungblut at mmm dot com wrote:
Hi,
I know I have seen this question posed before, but I can't seem to
find it in the FAQ or in the archives. Sorry for the redundancy.
I only want to copy nodes that have a textual descendant.
<Catalog>
<Product NodeID="A" Action="A">
<Child>
<Grandchild/>
</Child>
</Product>
<Product NodeID="B" Action="A">
<Child>
<Grandchild>Steven</Grandchild>
</Child>
</Product>
<Product NodeID="C" Action="A">
<Child>
<Grandchild>Paul</Grandchild>
<Grandchild/>
</Child>
</Product>
<Product NodeID="D" Action="A"/>
</Catalog>
I would expect the results to look like the following:
<Catalog>
<Product NodeID="B" Action="A">
<Child>
<Grandchild>Steven</Grandchild>
</Child>
</Product>
<Product NodeID="C" Action="A">
<Child>
<Grandchild>Paul</Grandchild>
</Child>
</Product>
</Catalog>
If somebody has a link or a solution to this problem, I would appreciate
it.
Thanks,
Matt Youngblut
__________________________________________________
Do You Yahoo!?
Listen to your Yahoo! Mail messages from any phone.
http://phone.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list