[Home] [By Thread] [By Date] [Recent Entries]
At 2010-02-11 00:07 +0200, Israel Viente wrote:
I want to remove span elements that have empty text nodes and no further descendants. In case the p has ONLY empty spans I want to remove it alltogether. Did you try: <xsl:template match="p[span[normalize-space(.)='' and not(*)] and
not(span[normalize-space() or *]) and
not(*[not(self::span)])]"/>... which will remove the paragraph if there is at least one empty span, no non-empty spans, and nothing other than a span element child. A working illustration for XSLT 1 is below. For XSLT 2 you can use: <xsl:template match="p[span[normalize-space(.)='' and not(*)] and
not(span[normalize-space() or *]) and
not(* except span)]"/>I hope this helps. . . . . . . . . . . Ken T:\ftemp>type israel.xml <test> <p dir="rtl"><span id="textStyle10"></span></p> <p dir="rtl"><span id="textStyle10">Some text.</span> <span id="textStyle10"></span></p> <p dir="rtl"><span id="textStyle10"></span><sup>1</sup></p> <p dir="rtl"><span id="textStyle10"><br /><br /></span></p> </test> T:\ftemp>xslt israel.xml israel.xsl <?xml version="1.0" encoding="utf-8"?><test> <p dir="rtl"><span id="textStyle10">Some text.</span> </p>
<p dir="rtl"><sup>1</sup></p>
<p dir="rtl"><span id="textStyle10"><br/><br/></span></p>
</test>
T:\ftemp>type israel.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"><xsl:template match="p[span[normalize-space(.)='' and not(*)] and
not(span[normalize-space() or *]) and
not(*[not(self::span)])]"/><xsl:template match="span[not(*) and not(normalize-space(.))]"> </xsl:template> <xsl:template match="@*|node()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template></xsl:stylesheet> T:\ftemp>
|

Cart



