title: XSL Removing Empty Elements After Transformation
body: <p>I need to write an extensive XSLT that doesn't output (removes) any element that is empty. For Attributes, this means that if the value of the path is empty, it will not populate that attribute in the output. For Nodes, this means that if there isn't any data (empty attributes or child nodes without attributes/data) it will not populate that node in the output. Below is an example related to Baseball to better explain what I'm looking for.</p>
  
  <p>How the output looks like now:</p>
  
  <pre><code>  &lt;Baseball&gt;
      &lt;Fields&gt;
        &lt;Equipment&gt;
          &lt;Bats&gt;
            &lt;Bat Brand="Louisville" Model="16534" Length="34" Weight="30" Description="Composite" /&gt;
            &lt;Bat Brand="Easton" Model="asdfer" Length="32" Weight="29" Description="" /&gt;
            &lt;Bat Brand="" Model="" Length="" Weight="" Description="" /&gt;
          &lt;/Bats&gt;
          &lt;Gloves&gt;
            &lt;Glove Brand="" Model="" Length="" Description="" /&gt;
          &lt;/Gloves&gt;
        &lt;/Equipment&gt;
      &lt;/Fields&gt;
    &lt;/Baseball&gt;
  </code></pre>
  
  <p>How I need the output to look like:</p>
  
  <pre><code>&lt;Baseball&gt;
      &lt;Fields&gt;
        &lt;Equipment&gt;
          &lt;Bats&gt;
            &lt;Bat Brand="Louisville" Model="16534" Length="34" Weight="30" Description="Composite" /&gt;
            &lt;Bat Brand="Easton" Model="asdfer" Length="32" Weight="29" /&gt;
          &lt;/Bats&gt;
        &lt;/Equipment&gt;
      &lt;/Fields&gt;
    &lt;/Baseball&gt;
  </code></pre>
  
  <p>I know I can solve this issue by writing  to check the value but given the length of the transformation, I would like to avoid this if at all possible. In addition, give the structure of the XML that I will be drawing from, attributes for a given output node will have paths that differentiate from each other. For Example, the attribute "Brand" in the output node "Bat" might have a path of "ab/cd/ef/brand" while the attribute "Model" might have a path "ab/wx/yz/model". (I know my Baseball example above is not conducive to this point). Is there a way to achieve this without writing two XSLTs? Can you pass back through the output in XSLT?</p>