Altova Mailing List Archives


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

From: "G. Ken Holman" <gkholman@-------------------->
To:
Date: 12/4/2008 12:35:00 PM
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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.