Shanmugalakshmi
Shanmugalakshmi

Reputation: 267

Removing specific empty tags from XML through XSLT

I have an XML of the following process

<p>In technical jargon<sup></sup>, the expect<span class="insert"></span><span class="insert"></span><span class="insert">ed</span> excess return on a factor is proportional to the negative of the factor covariance with the pricing kernel, <br/>given by marginal utility of consumption for a representative agent.</p>

I used the following xsl to remove span empty tag.

<xsl:template match=
    "*[not(span) 
     and normalize-space()=''
      ]"/>

Output through XSL. It remove all empty tags.

<p>In technical jargon, the expect<span class="insert">ed</span> excess return on a factor is proportional to the negative of the factor covariance with the pricing kernel, given by marginal utility of consumption for a representative agent.</p>

But Remove span empty tag only. So I need following XML

<p>In technical jargon<sup></sup>, the expect<span class="insert">ed</span> excess return on a factor is proportional to the negative of the factor covariance with the pricing kernel, <br/>given by marginal utility of consumption for a representative agent.</p>

Thanks for advance.

Upvotes: 0

Views: 247

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122364

If you only want to delete spans then make the template only match spans

<xsl:template match="span[not(span) 
     and normalize-space()='']"/>

Upvotes: 1

Joel M. Lamsen
Joel M. Lamsen

Reputation: 7173

use

<xsl:template match=
        "*[self::span 
        and normalize-space()=''
        ]"/>

Upvotes: 1

Related Questions