如何删除包含文本内容的表行

时间:2016-06-01 11:32:56

标签: xml xslt

我尝试删除td具有class = feldtyp1且文本内容为<p>News</p>的每个表行。

到目前为止,我已经删除了整行。 现在我仍然需要查询具有类feldtyp1的单元格是否包含文本内容新闻

有人可以帮助我吗?

我的源XML的一部分

<table class="feldtyp">
   <tr>
      <td class="feldtyp1"><p>Feldtyp</p></td>
      <td class="feldtyp2"><p>Text</p></td>
   </tr>
   <tr>
      <td class="feldtyp1"><p>News</p></td>
      <td class="feldtyp2"><p>Text</p></td>
   </tr>
</table>

我当前的XLS会删除所有行

<xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="node()|@*">
      <xsl:copy>
         <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
    </xsl:template>
    <xsl:template match="tr|td[@class='feldtyp1']"/>
    <xsl:template match="tr|td[@class='feldtyp2']"/>
</xsl:stylesheet>

所需的结果应如下所示

<table class="feldtyp">
   <tr>
      <td class="feldtyp1"><p>Feldtyp</p></td>
      <td class="feldtyp2"><p>Text</p></td>
   </tr>
</table>

1 个答案:

答案 0 :(得分:1)

  

我尝试删除每个表行,其中td具有class = feldtyp1和   文字内容为<p>News</p>

这并不完全清楚。假设您要删除包含类为#34; feldtyp1&#34;的单元格的任何行。它(相同的单元格)有一个<p>News</p>子元素,你应该这样做:

<xsl:template match="tr[td[@class='feldtyp1'and p[.='News']]]"/>