2012-08-09 72 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']"/>