Java – how to keep empty XML tags after XSLT – prevent them from collapsing into

Say I have a very simple XML, an empty tag 'B':

<Root>
  <A>foo</A>
  <B></B>
  <C>bar</C>
</Root>

I'm using XSLT to remove several tags, such as "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>

So far, I can, but the problem is that I finally have such an output:

<Root>
  <A>foo</A>
  <B/>
</Root>

When I really want to:

<Root>
  <A>foo</A>
  <B></B>
</Root>

Is there any way to prevent "B" from collapsing?

thank you.

Solution

OK, so this is useful for me:

<xsl:output method="html">
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>