title: Remove empty XML elements in Java
body: <p>i have an output XML which contains empty elements and also empty elements but with attributes.</p>
  
  <p>i checked some older post which help me to solve a part of my problem.</p>
  
  <p>i used the following XSLT solution</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;   &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:if test=". != '' or ./@* != ''"&gt;
        &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="@*|node()"/&gt;
        &lt;/xsl:copy&gt;
      &lt;/xsl:if&gt;   &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>but the problem is that remove also elements having child elements with attributes like</p>
  
  <pre><code>&lt;CurrencyList&gt; 
  &lt;Currency code="EURO"/&gt; 
  &lt;Currency code="USD"/&gt;
  &lt;/CurrencyList&gt;
  </code></pre>
  
  <p>anyone have an idea how to solve this problem ?</p>
  
  <p>Many thanks</p>