The overall goal is to remove all empty nodes--including nodes which would be made empty if the child empty nodes were removed. The following:
<xsl:template match="*[not(node())]"/>
will remove empty nodes, but will leave empty nodes that had only empty nodes in them prev开发者_JAVA百科iously. I think I need an xpath that will match all nodes that all descendants of which have no attributes and no text nodes (ignoring whitespace).
Use:
<xsl:template match="*[not(.//@*) and not(descendent::text())]"/>
Notice the and
operator. Using or
does not solve the problem.
I think I found the answer...
<xsl:template match="*[not(.//text() | .//@*)]"/>
Just find all nodes that have no descendant text or attributes, right? Is there something I'm missing such that this won't do what I think it will in some cases? In my simple test, this seemed to work.
精彩评论