my xslt returns closed tags - (category and description tags) when either of them is empty. In the below example, Title with return closed description tag while Title2 will return closed category tag. 

I am feeding my source into an application and because there are closed tags with no opening, I do not get the expected result.

**This is my input:**

```
    <?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
    <title>Title</title>
    <description>Description</description>
    <link>https://url/</link>
    <language>en-us</language>
    <lastBuildDate>Sun, 27 Sep 2015 21:07:40 GMT</lastBuildDate>

    <image>
    <title>Title</title>
    <width>144</width><height>400</height>
    <link>https://url</link>
    <url>https://url</url>
    </image>

    <item>
    <title>Title</title>
    <link>https://html</link>
    <guid isPermaLink="true">https://html</guid>
    <comments>https://html</comments>
    <pubDate>Thu, 24 Sep 2015 16:01:42 GMT</pubDate>
    <description><![CDATA[]]></description>
    <category>headline,government,usa,spyware</category>
    </item>

    <item>
    <title>Title2</title>
    <link>https://txt</link>
    <guid isPermaLink="true">https://txt</guid>
    <comments>https://html</comments>
    <pubDate>Fri, 25 Sep 2015 06:54:51 GMT</pubDate>
    <description>DescritpionExist</description>
    <category></category>
    </item>

    </channel>
    </rss>

```

**Following is my XSLT:**

```
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!--skips new lines and indents in-->    
    <xsl:output method="xml" indent="yes"/> 
    <!--if,error-->
    <xsl:strip-space elements="*"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <!--skips completely-->
    <xsl:template match="channel/title"/>
    <xsl:template match="channel/description"/>
    <xsl:template match="channel/link"/>
    <xsl:template match="channel/language"/>
    <xsl:template match="channel/lastBuildDate"/>
    <xsl:template match="image"/>
    <xsl:template match="item/link"/>

    <!--skips node if empty-->
    <xsl:template match="item/title[not(child::node())]"/>
    <xsl:template match="item/link[not(child::node())]"/>
    <xsl:template match="item/guid[not(child::node())]"/>
    <xsl:template match="item/comments[not(child::node())]"/>

    <!--delimits values if seperated by comma-->
    <xsl:template match="item/category[contains(.,',')]">  
        <xsl:variable name="elementName" select="name(..)"/>

        <xsl:call-template name="splitIntoElements">
            <xsl:with-param name="baseName" select="name(..)" />
            <xsl:with-param name="txt" select="." />    
        </xsl:call-template>

    </xsl:template>

    <xsl:template name="splitIntoElements">
        <xsl:param name="baseName" />
        <xsl:param name="txt" />
        <xsl:param name="delimiter" select="','" />
        <xsl:param name="index" select="1" />

        <xsl:variable name="first" select="substring-before($txt, $delimiter)" />
        <xsl:variable name="remaining" select="substring-after($txt, $delimiter)" />

        <xsl:element name="{$baseName}-{$index}">
            <xsl:choose>
                <xsl:when test="$first">
                    <xsl:value-of select="$first" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$txt" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:element>     
        <xsl:if test="$remaining">
            <xsl:call-template name="splitIntoElements">
                <xsl:with-param name="baseName" select="$baseName" />
                <xsl:with-param name="txt" select="$remaining" />
                <xsl:with-param name="index" select="$index+1" />
                <xsl:with-param name="delimiter" select="$delimiter" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

```

**Skipping or removing empty fields did not help:**

```
<xsl:template match="item/category[not(child::node())]"/>
<xsl:template match="item/description[not(child::node())]"/>

```

nor this helped

```
<xsl:template match="*[normalize-space() = '']" />

```

I even tried to exhaust if then clause to add an opening tag before the closing tag, but I was not able to get the result.

My output is:

```
<item>
             <title>Title</title>
             <guid isPermaLink="true">http</guid>
             <comments>http</comments>
             <pubDate>Thu, 24 Sep 2015 01:54:35 GMT</pubDate>
             <description/>
             <item-1>headline</item-1>
             <item-2>government</item-2>
             <item-3>privacy</item-3>
             <item-4>usa</item-4>
          </item>
          <item>
             <title>Title2</title>
             <guid isPermaLink="true">http</guid>
             <comments>comment</comments>
             <pubDate>Sat, 26 Sep 2015 03:14:57 GMT</pubDate>
             <description>Description</description>
             <category/>
          </item>

```

Expected output should be:

```
<item>
         <title>Title</title>
         <guid isPermaLink="true">http</guid>
         <comments>http</comments>
         <pubDate>Thu, 24 Sep 2015 01:54:35 GMT</pubDate>
         <description><description/>
         <item-1>headline</item-1>
         <item-2>government</item-2>
         <item-3>privacy</item-3>
         <item-4>usa</item-4>
      </item>
      <item>
         <title>Title2</title>
         <guid isPermaLink="true">http</guid>
         <comments>comment</comments>
         <pubDate>Sat, 26 Sep 2015 03:14:57 GMT</pubDate>
         <description>Description</description>
         <category><category/>
      </item>

```