Reputation: 49
In document below I am trying to get those element have no text child. but every effort get nothing.
<a>
<b>
<c> this is nice place </c>
</b>
<d>
<e> where this place is </e>
<f> this place is very close to us</f>
</d>
<g>
<h/>
</g>
<i/>
</a>
Upvotes: 1
Views: 47
Reputation: 3517
So if I understand correctly, you want all the children of a
which have no text nodes?
/a/element()[not(.//text())]
Upvotes: 0
Reputation: 11915
Stylesheet that copies empty elements (immediate children of a
) and their children, if there's not a single text node:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:apply-templates select="a"/>
</xsl:template>
<xsl:template match="a">
<empty>
<xsl:copy-of select="*[not(node()/text())]"/>
</empty>
</xsl:template>
</xsl:stylesheet>
Result:
<?xml version="1.0" encoding="utf-8"?>
<empty>
<g>
<h />
</g>
<i />
</empty>
Upvotes: 0