Re: [xsl] removing nodes to parent based on all child nodes not having text value

Subject: Re: [xsl] removing nodes to parent based on all child nodes not having text value
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 04 Dec 2008 07:34:21 -0500
At 2008-12-04 10:15 +0000, Vasu Chakkera wrote:
> <xsl:template match="node()|@*">
> <xsl:copy>
>  <xsl:apply-templates select="node()|@*"/>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="*[not(descendant::text())]"/>
> </xsl:stylesheet>

That was not complete ..

The below is what i meant..

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>


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

Be aware, Vasu, that her input data was indented, and you and I have proposed XSLT 1.0 results, and in that data model it is most likely (though not with Microsoft) that the white-space-only text nodes will all be present in the data model, thus your proposal will only get rid of empty leaf elements. Any other element will have indentation white-space-only text nodes. In a data fragment where there is a subtree of elements but no non-white-space-only text nodes, your stylesheet will preserve that tree rather than ignore it as I think the original poster wants.


And dealing with indentation is even more uncertain in XSLT 2.0 implementations where invocation options change the nature of the source tree presented to the stylesheet.

In all of my stylesheets I've very rarely ever needed to explicitly address text nodes, or the testing of element node values, without some qualification due to the uncertainty of indentation and of mixed content.

I hope this is considered helpful.

. . . . . . . . . . . Ken

--
Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes:
:  Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video sample lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg
Video course overview:  http://www.youtube.com/watch?v=VTiodiij6gE
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread