title: XSLT 1.0- Redundant tags after applying transformation
body: <p>I have a sample XML file like below;</p>
  
  <pre><code>&lt;ItemList&gt;
    &lt;Item&gt;
      &lt;Name&gt;1&lt;/Name&gt;
      &lt;Lon&gt;66.406180329538&lt;/Lon&gt;
      &lt;Lat&gt;35.7185924672465&lt;/Lat&gt;
  
    &lt;/Item&gt;
    &lt;Item&gt;
      &lt;Name&gt;2&lt;/Name&gt;
      &lt;cx&gt;1&lt;/cx&gt;
      &lt;cy&gt;2&lt;/cy&gt;
      &lt;rx&gt;3&lt;/rx&gt;
      &lt;ry&gt;4&lt;/ry&gt;
    &lt;/Item&gt;
  &lt;/ItemList&gt; 
  </code></pre>
  
  <p>I want to create a xslt file that handles if Item has "Lon" node then it must create a Point object, if item has a "cx" node it must create a "Circle" object.</p>
  
  <p>For this purpose , I created a xslt file like below;</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"&gt;
      &lt;xsl:output method="xml" encoding="UTF-8" indent="yes"/&gt;
      &lt;xsl:template match="/"&gt;
          &lt;xsl:variable name="var1_initial" select="."/&gt;
          &lt;ItemList xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"&gt;
              &lt;xsl:attribute name="xsi:noNamespaceSchemaLocation" namespace="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;/xsl:attribute&gt;
              &lt;xsl:for-each select="ItemList/Item"&gt;
                  &lt;xsl:variable name="var2_cur" select="."/&gt;
                  &lt;Item&gt;
                      &lt;CommonMetadata&gt;
                          &lt;xsl:for-each select="Name"&gt;
                              &lt;xsl:variable name="var3_cur" select="."/&gt;
                              &lt;Description&gt;
                                  &lt;xsl:value-of select="."/&gt;
                              &lt;/Description&gt;
                          &lt;/xsl:for-each&gt;
  
                          &lt;Geography&gt;
                              &lt;KMLRepresentation&gt;
                                  &lt;kml:kml&gt;
                                      &lt;kml:Folder&gt;
                                          &lt;kml:Placemark&gt;
  
                                             &lt;kml:Circle&gt;
                                                  &lt;xsl:for-each select="cx"&gt;
                                                      &lt;xsl:variable name="var4_cur" select="."/&gt;
                                                      &lt;xsl:attribute name="cx"&gt;
                                                          &lt;xsl:value-of select="number(.)"/&gt;
                                                      &lt;/xsl:attribute&gt;
                                                  &lt;/xsl:for-each&gt;
                                                  &lt;xsl:for-each select="cy"&gt;
                                                      &lt;xsl:variable name="var5_cur" select="."/&gt;
                                                      &lt;xsl:attribute name="cy"&gt;
                                                          &lt;xsl:value-of select="number(.)"/&gt;
                                                      &lt;/xsl:attribute&gt;
                                                  &lt;/xsl:for-each&gt;
                                                  &lt;xsl:for-each select="rx"&gt;
                                                      &lt;xsl:variable name="var6_cur" select="."/&gt;
                                                      &lt;xsl:attribute name="r"&gt;
                                                          &lt;xsl:value-of select="number(.)"/&gt;
                                                      &lt;/xsl:attribute&gt;
                                                  &lt;/xsl:for-each&gt;
                                              &lt;/kml:Circle&gt;
  
  
                                            &lt;kml:Point&gt;
                                                  &lt;xsl:for-each select="Lon"&gt;
                                                      &lt;xsl:variable name="var7_cur" select="."/&gt;
                                                      &lt;xsl:for-each select="$var2_cur/Lat"&gt;
                                                          &lt;xsl:variable name="var8_cur" select="."/&gt;
                                                          &lt;kml:coordinates&gt;
                                                              &lt;xsl:value-of select="concat($var7_cur, ',', .)"/&gt;
                                                          &lt;/kml:coordinates&gt;
                                                      &lt;/xsl:for-each&gt;
                                                  &lt;/xsl:for-each&gt;
                                              &lt;/kml:Point&gt;
  
                                &lt;/kml:Placemark&gt;
                                      &lt;/kml:Folder&gt;
                                  &lt;/kml:kml&gt;
                              &lt;/KMLRepresentation&gt;
                          &lt;/Geography&gt;
                      &lt;/CommonMetadata&gt;
                  &lt;/Item&gt;
              &lt;/xsl:for-each&gt;
          &lt;/ItemList&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>But after applying this xslt file there are empty tags like <code>&lt;kml:Point/&gt;</code> in the Circle object and <code>&lt;kml:Circle/&gt;</code> tag in the Point object. I do not these redundant tags. If Item has "cx" node, transformed Circle object should not have empty  tag.</p>
  
  <p>This is my sample output ;</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ItemList&gt;
      &lt;Item&gt;
          &lt;CommonMetadata&gt;
              &lt;Description&gt;1&lt;/Description&gt;
  
              &lt;Geography&gt;
                  &lt;KMLRepresentation&gt;
                      &lt;kml:kml&gt;
                          &lt;kml:Folder&gt;
                              &lt;kml:Placemark&gt;
                                  &lt;kml:Circle/&gt;
                                  &lt;kml:Point&gt;
                                      &lt;kml:coordinates&gt;66.406180329538,35.7185924672465&lt;/kml:coordinates&gt;
                                  &lt;/kml:Point&gt;
                              &lt;/kml:Placemark&gt;
                          &lt;/kml:Folder&gt;
                      &lt;/kml:kml&gt;
                  &lt;/KMLRepresentation&gt;
              &lt;/Geography&gt;    
          &lt;/CommonMetadata&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;CommonMetadata&gt;
              &lt;Description&gt;2&lt;/Description&gt;            
              &lt;Geography&gt;
                  &lt;KMLRepresentation&gt;
                      &lt;kml:kml&gt;
                          &lt;kml:Folder&gt;
                              &lt;kml:Placemark&gt;
                                  &lt;kml:Circle cx="1" cy="2" r="3"/&gt;
                                  &lt;kml:Point/&gt;
                              &lt;/kml:Placemark&gt;
                          &lt;/kml:Folder&gt;
                      &lt;/kml:kml&gt;
                  &lt;/KMLRepresentation&gt;
              &lt;/Geography&gt;
  
          &lt;/CommonMetadata&gt;
      &lt;/Item&gt;
  &lt;/ItemList&gt;
  </code></pre>
  
  <p>I have tried <code>xsl:if test</code> and <code>xsl:when test</code> functions but I could not manage it again. Could you please help about my problem ?</p>