Tiago Fernandez Tiago Fernandez - 2 years ago 143
Java Question

How to preserve Empty XML Tags after XSLT - prevent collapsing them from <B></B> to <B/>

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


I'm currently using XSLT to remove a few tags, like 'C' for example:

<?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-of select="@*" />
<xsl:apply-templates />

<xsl:template match="C" />


So far OK, but the problem is I end up having an output like this:


when I actually really want:


Is there a way to prevent 'B' from collapsing?


Answer Source

Ok, so here what worked for me:

<xsl:output method="html">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download