如何使用 xslt 删除特定元素而不是其中的文本

how to remove specific elements but not the text inside it using xslt

这是我的输入 xml

<para>
<a><b>this is a text</b></a>
</para>

这是我的预期输出

<para>
this is a text
</para>

我怎样才能删除所有 "a" 标签和 "b" 标签,并且文本不会受到使用 xslt 的影响谢谢

从身份转换模板开始

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

然后添加

<xsl:template match="a | b">
  <xsl:apply-templates/>
</xsl:template>

处理您的元素。

<xsl:template match="//para">
   <xsl:copy>
      <xsl:value-of select="."></xsl:value-of>
   </xsl:copy>
</xsl:template>

(或者为了避免来自其他子元素的白色 space:

<xsl:template match="//para">
   <xsl:copy>
      <xsl:value-of select="./*/*/text()"></xsl:value-of>
   </xsl:copy>
</xsl:template>

问题解决..

<xsl:strip-space elements="*"/>
 <xsl:template match="*">
        <xsl:copy>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>

<xsl:template match="//*/text()">
  <xsl:if test="normalize-space(.)">
    <xsl:value-of select=
     "concat(normalize-space(.), '&#xA;')"/>
  </xsl:if>
  <xsl:apply-templates />
</xsl:template>
<xsl:template match="*[not(node())]" />