通过XSLT从XML中删除特定的空标记

时间:2014-05-29 08:18:59

标签: xslt

我有以下过程的XML

<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>

我使用以下xsl删除span空标记。

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

通过XSL输出。它会删除所有空标记。

<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>

但仅删除span空标记。所以我需要遵循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>

感谢您提前。

2 个答案:

答案 0 :(得分:1)

使用

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

答案 1 :(得分:1)

如果您只想删除跨度,请使模板仅匹配跨度

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