2012-08-09 69 views
1

我有这样的XML结构,只是一些有效的XML结构与HTML标签混合。我试图在该部分中匹配<p>MyHeader</p>并将其设置为空。xslt匹配和剥离

即在此结构上运行XSLT后,我不想打印<p>MyHeader</p>标记。

<abstract> 
<section> 
<p>MyHeader</p> 

<p> other content in section </p> 
<h1> other content in section </h1> 

</section> 
</abstract> 

这里是我的XSL

<xsl:template match="abstract/section/p"> 
     <xsl:choose> 
      <xsl:when test="text() ='MyHeader'"></xsl:when> 
      <xsl:otherwise><xsl:apply-templates /></xsl:otherwise> 
     </xsl:choose> 
</xsl:template> 

上有什么错我上面的代码中的任何想法我试图?我没有看到<p>MyHeader</p>标签被剥离。

+0

乍一看,这应该工作,所以我觉得这个问题可能在于你的XSLT的另一部分。例如,其他一些模板可能与** p **元素匹配。如果可能,您可以发布完整的XSLT文件吗?谢谢! – 2012-08-09 11:53:47

+0

我同意发布的样本应该可以工作,但我强烈建议将模板缩短为'',该元素和你的'xsl:否'是由内置模板完成的。 – 2012-08-09 12:33:51

回答

0
<xsl:template match="abstract/section/p"> 
     <xsl:choose> 
      <xsl:when test="text() ='MyHeader'"></xsl:when> 
      <xsl:otherwise><xsl:apply-templates /></xsl:otherwise> 
     </xsl:choose> 
</xsl:template> 

what's wrong with my code 

没有错所示的代码 - 问题是在你还没有向我们展示的代码。

猜测

  • 模板未选择用于执行。
  • 有一个明确的<xsl:copy-of>选择这个p元素。

建议:只要使用

<xsl:template match="abstract/section/p[.='MyHeader']"/>