title: Remove empty nodes from XML using XSLT
body: <p>I am having trouble removing empty nodes from my XML using XSLT. For example, this area in the XSLT:</p>
  
  <pre><code>             &lt;RCPNT_NM&gt;
                  &lt;snm&gt;
                      &lt;xsl:value-of select="SNM"/&gt;
                  &lt;/snm&gt;
                  &lt;gv_nm&gt;
                      &lt;xsl:value-of select="GVN_NM"/&gt;
                  &lt;/gv_nm&gt;
                  &lt;init&gt;
                      &lt;xsl:value-of select="INIT"/&gt;
                  &lt;/init&gt;
              &lt;/RCPNT_NM&gt;
  </code></pre>
  
  <p>The data inside some of those nodes is completely empty, but I am still getting them back. I tried applying the <code>match="node()|@*"</code> template area to the xslt, but that didn;t work either. Here is the entire XSLT file:</p>
  
  <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0"&gt;
  &lt;xsl:output encoding="UTF-8" indent="yes" method="xml" version="1.0"/&gt;
  &lt;xsl:output indent="yes" omit-xml-declaration="yes"/&gt;
  &lt;xsl:strip-space elements="*"/&gt;
  &lt;xsl:template match="/"&gt;
      &lt;Return&gt;
          &lt;xsl:apply-templates select="//IPERSON/item"/&gt;
      &lt;/Return&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="node()|@*"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="node()|@*"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="*[not(@*) and not(*) and (not(text()) )]"/&gt;
  &lt;xsl:template match="IPERSON/item"&gt;
      &lt;T5018Slip&gt;
          &lt;RCPNT_NM&gt;
              &lt;snm&gt;
                  &lt;xsl:value-of select="SNM"/&gt;
              &lt;/snm&gt;
              &lt;gv_nm&gt;
                  &lt;xsl:value-of select="GVN_NM"/&gt;
              &lt;/gv_nm&gt;
              &lt;init&gt;
                  &lt;xsl:value-of select="INIT"/&gt;
              &lt;/init&gt;
          &lt;/RCPNT_NM&gt;
          &lt;sin&gt;
              &lt;xsl:value-of select="SIN"/&gt;
          &lt;/sin&gt;
          &lt;rcpnt_bn&gt;
              &lt;xsl:value-of select="RCPNT_BN"/&gt;
          &lt;/rcpnt_bn&gt;
          &lt;CORP_PTNRP_NM&gt;
              &lt;l1_nm&gt;
                  &lt;xsl:value-of select="CORPL1_NM"/&gt;
              &lt;/l1_nm&gt;
              &lt;l2_nm&gt;
                  &lt;xsl:value-of select="CORPL2_NM"/&gt;
              &lt;/l2_nm&gt;
          &lt;/CORP_PTNRP_NM&gt;
          &lt;rcpnt_tcd&gt;
              &lt;xsl:value-of select="RCPNT_TCD"/&gt;
          &lt;/rcpnt_tcd&gt;
          &lt;RCPNT_ADDR&gt;
              &lt;addr_l1_txt&gt;
                  &lt;xsl:value-of select="ADDR_L1_TXT"/&gt;
              &lt;/addr_l1_txt&gt;
              &lt;addr_l2_txt&gt;
                  &lt;xsl:value-of select="ADDR_L2_TXT"/&gt;
              &lt;/addr_l2_txt&gt;
              &lt;cty_nm&gt;
                  &lt;xsl:value-of select="CTY_NM"/&gt;
              &lt;/cty_nm&gt;
              &lt;prov_cd&gt;
                  &lt;xsl:value-of select="PROV_CD"/&gt;
              &lt;/prov_cd&gt;
              &lt;cntry_cd&gt;
                  &lt;xsl:value-of select="CNTRY_CD"/&gt;
              &lt;/cntry_cd&gt;
              &lt;pstl_cd&gt;
                  &lt;xsl:value-of select="PSTL_CD"/&gt;
              &lt;/pstl_cd&gt;
          &lt;/RCPNT_ADDR&gt;
          &lt;bn&gt;
              &lt;xsl:value-of select="BN"/&gt;
          &lt;/bn&gt;
          &lt;sbctrcr_amt&gt;
              &lt;xsl:value-of select="SBCTRCR_AMT"/&gt;
          &lt;/sbctrcr_amt&gt;
          &lt;rpt_tcd&gt;
              &lt;xsl:value-of select="RPT_TCD"/&gt;
          &lt;/rpt_tcd&gt;
      &lt;/T5018Slip&gt;
      &lt;xsl:for-each select="Return/T5018Summary/slp_cnt"&gt;
          &lt;xsl:value-of select="SLP_CNT='1'"/&gt;
          &lt;xsl:if test="slp_cnt='1'"&gt;
              &lt;T5018Summary&gt;
                  &lt;bn&gt;
                      &lt;xsl:value-of select="BN1"/&gt;
                  &lt;/bn&gt;
                  &lt;PAYR_NM&gt;
                      &lt;l1_nm&gt;
                          &lt;xsl:value-of select="L1_NM"/&gt;
                      &lt;/l1_nm&gt;
                      &lt;l2_nm&gt;
                          &lt;xsl:value-of select="L2_NM"/&gt;
                      &lt;/l2_nm&gt;
                      &lt;l3_nm&gt;
                          &lt;xsl:value-of select="L3_NM"/&gt;
                      &lt;/l3_nm&gt;
                  &lt;/PAYR_NM&gt;
                  &lt;PAYR_ADDR&gt;
                      &lt;addr_l1_txt&gt;
                          &lt;xsl:value-of select="PAYRADDR_L1_TXT"/&gt;
                      &lt;/addr_l1_txt&gt;
                      &lt;addr_l2_txt&gt;
                          &lt;xsl:value-of select="PAYRADDR_L2_TXT"/&gt;
                      &lt;/addr_l2_txt&gt;
                      &lt;cty_nm&gt;
                          &lt;xsl:value-of select="PAYRCTY_NM"/&gt;
                      &lt;/cty_nm&gt;
                      &lt;prov_cd&gt;
                          &lt;xsl:value-of select="PAYRPROV_CD"/&gt;
                      &lt;/prov_cd&gt;
                      &lt;cntry_cd&gt;
                          &lt;xsl:value-of select="PAYRCNTRY_CD"/&gt;
                      &lt;/cntry_cd&gt;
                      &lt;pstl_cd&gt;
                          &lt;xsl:value-of select="PAYRPSTL_CD"/&gt;
                      &lt;/pstl_cd&gt;
                  &lt;/PAYR_ADDR&gt;
                  &lt;CNTC&gt;
                      &lt;cntc_nm&gt;
                          &lt;xsl:value-of select="CNTC_NM"/&gt;
                      &lt;/cntc_nm&gt;
                      &lt;cntc_area_cd&gt;
                          &lt;xsl:value-of select="CNTC_AREA_CD"/&gt;
                      &lt;/cntc_area_cd&gt;
                      &lt;cntc_phn_nbr&gt;
                          &lt;xsl:value-of select="CNTC_PHN_NBR"/&gt;
                      &lt;/cntc_phn_nbr&gt;
                      &lt;cntc_extn_nbr&gt;
                          &lt;xsl:value-of select="CNTC_EXTN_NBR"/&gt;
                      &lt;/cntc_extn_nbr&gt;
                  &lt;/CNTC&gt;
                  &lt;PRD_END_DT&gt;
                      &lt;dy&gt;
                          &lt;xsl:value-of select="DY"/&gt;
                      &lt;/dy&gt;
                      &lt;mo&gt;
                          &lt;xsl:value-of select="MO"/&gt;
                      &lt;/mo&gt;
                      &lt;yr&gt;
                          &lt;xsl:value-of select="YR"/&gt;
                      &lt;/yr&gt;
                  &lt;/PRD_END_DT&gt;
                  &lt;slp_cnt&gt;
                      &lt;xsl:value-of select="SLP_CNT"/&gt;
                  &lt;/slp_cnt&gt;
                  &lt;tot_sbctrcr_amt&gt;
                      &lt;xsl:value-of select="TOT_SBCTRCR_AMT"/&gt;
                  &lt;/tot_sbctrcr_amt&gt;
                  &lt;rpt_tcd&gt;
                      &lt;xsl:value-of select="RPT_TCD"/&gt;
                  &lt;/rpt_tcd&gt;
              &lt;/T5018Summary&gt;
          &lt;/xsl:if&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>