title: Is it possible to detect the presence of a (xml) tag using XSLT?
body: <p>I am suppose to test the presence of a tag and create a new node according to the result ..</p>
  
  <p>This is the input XML :</p>
  
  <pre><code>&lt;root&gt; 
    &lt;tag1&gt;NS&lt;/tag1&gt; 
    &lt;tag2 id="8"&gt;NS&lt;/tag2&gt; 
    &lt;test&gt; 
      &lt;other_tag&gt;text&lt;/other_tag&gt; 
      &lt;main&gt;Y&lt;/main&gt; 
    &lt;/test&gt; 
    &lt;test&gt; 
      &lt;other_tag&gt;text&lt;/other_tag&gt; 
    &lt;/test&gt; 
  &lt;/root&gt; 
  </code></pre>
  
  <p>And the required output XML is :</p>
  
  <pre><code>&lt;root&gt; 
    &lt;tag1&gt;NS&lt;/tag1&gt; 
    &lt;tag2 id="8"&gt;NS&lt;/tag2&gt; 
    &lt;test&gt; 
      &lt;other_tag&gt;text&lt;/other_tag&gt; 
      &lt;Main_Tag&gt;Present&lt;/Main_Tag&gt; 
    &lt;/test&gt; 
    &lt;test&gt; 
      &lt;other_tag&gt;text&lt;/other_tag&gt; 
      &lt;Main_Tag&gt;Absent&lt;/Main_Tag&gt;
    &lt;/test&gt; 
  &lt;/root&gt; 
  </code></pre>
  
  <p>I know to test the value of the tag, but this is something new to me.</p>
  
  <p>I tried using this Template :
  (which is not working as per the requirement)</p>
  
  <pre><code>   &lt;xsl:template match="test"&gt; 
        &lt;xsl:element name="test"&gt; 
          &lt;xsl:for-each select="/root/test/*"&gt; 
        &lt;xsl:choose&gt; 
          &lt;xsl:when test="name()='bbb'"&gt; 
            &lt;xsl:element name="Main_Tag"&gt; 
              &lt;xsl:text&gt;Present&lt;/xsl:text&gt; 
            &lt;/xsl:element&gt; 
          &lt;/xsl:when&gt; 
          &lt;xsl:otherwise&gt; 
            &lt;xsl:element name="Main_Tag"&gt; 
            &lt;xsl:text&gt;Absent&lt;/xsl:text&gt; 
            &lt;/xsl:element&gt; 
          &lt;/xsl:otherwise&gt; 
        &lt;/xsl:choose&gt; 
          &lt;/xsl:for-each&gt; 
        &lt;/xsl:element&gt; 
    &lt;/xsl:template&gt; 
  </code></pre>