1

我有一个这样的 XML 结构,只是一些与 HTML 标记混合的有效 XML 结构。我正在尝试匹配<p>MyHeader</p>该部分并将其设置为空。

那是在这个结构上运行 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>标签被剥离。

4

1 回答 1

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']"/>
于 2012-08-09T12:33:18.460 回答