如何在XSLT之后保留空XML标记 - 防止它们从<B> </ B>折叠到<B />

Tia*_*dez 12 java xml xslt

假设我有一个非常简单的XML,带有空标记'B':

<Root>
  <A>foo</A>
  <B></B>
  <C>bar</C>
</Root>
Run Code Online (Sandbox Code Playgroud)

我目前正在使用XSLT删除一些标签,例如'C':

<?xml version="1.0" ?>

<xsl:stylesheet version="2.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="no" encoding="utf-8" omit-xml-declaration="yes" />

<xsl:template match="*">
    <xsl:copy>
        <xsl:copy-of select="@*" />
        <xsl:apply-templates />
    </xsl:copy>
</xsl:template>

<xsl:template match="C" />

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

到目前为止还好,但问题是我最终得到这样的输出:

<Root>
  <A>foo</A>
  <B/>
</Root>
Run Code Online (Sandbox Code Playgroud)

当我真正想要的时候:

<Root>
  <A>foo</A>
  <B></B>
</Root>
Run Code Online (Sandbox Code Playgroud)

有没有办法阻止'B'崩溃?

谢谢.

Tia*_*dez 9

好的,所以这里对我有用:

<xsl:output method="html">
Run Code Online (Sandbox Code Playgroud)