title: XSl:Variable - Condition to check whether value exist
body: <p>Using XSLT 1.0, how do I check whether the value in the variable exists or not?  </p>
  
  <p>I am assigning the value to the variable initially from my XML data and then need to check whether it exits or not:</p>
  
  <pre><code>&lt;xsl:variable name="DOC_TYPE"&gt;
    &lt;xsl:value-of select="name(./RootTag/*[1])"/&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:if test="string($DOC_TYPE) = ''"&gt;
    &lt;xsl:variable name="DOC_TYPE"&gt;
      &lt;xsl:value-of select="name(./*[1])"/&gt;
    &lt;/xsl:variable&gt;
  &lt;/xsl:if&gt;  
  </code></pre>
  
  <p>The above is not working as expected. What I need is if <code>&lt;RootTag&gt;</code> exists in my data then the variable should contain the child node below the <code>&lt;RootTag&gt;</code>. If <code>&lt;RootTag&gt;</code> does not exist then the DOC_TYPE should be the first Tag in my XML data.</p>
  
  <p>Thanks for your response.</p>