title: adding attribute to the node
body: <p>I am trying to add an attribute to the node if the child node value is equal to some string.</p>
  
  <p>I have a main.xml file</p>
  
  <pre><code>&lt;Employees&gt;    
   &lt;Employee&gt;     
   &lt;countryid&gt;32&lt;/countryid&gt;
   &lt;id name="id"&gt;1&lt;/id&gt;
   &lt;firstname &gt;ABC&lt;/firstname&gt;
   &lt;lastname &gt;XYZ&lt;/lastname&gt;     
   &lt;/Employee&gt;
   &lt;Employee&gt;     
   &lt;countryid&gt;100&lt;/countryid&gt;
   &lt;id name="id"&gt;2&lt;/id&gt;
   &lt;firstname &gt;ddd&lt;/firstname&gt;
   &lt;lastname &gt;ggg&lt;/lastname&gt;     
   &lt;/Employee&gt;
   &lt;/Employees&gt;    
  </code></pre>
  
  <p>So let's say if the country id is equal to 32 then it should add attribute country=32 to Employee node. The output should be like below :</p>
  
  <p>output.xml</p>
  
  <pre><code> &lt;Employees&gt;    
   &lt;Employee countryid="32"&gt;     
   &lt;countryid&gt;32&lt;/countryid&gt;
   &lt;id name="id"&gt;1&lt;/id&gt;
   &lt;firstname &gt;ABC&lt;/firstname&gt;
   &lt;lastname &gt;XYZ&lt;/lastname&gt;     
   &lt;/Employee&gt;
   &lt;Employee&gt;     
   &lt;countryid&gt;100&lt;/countryid&gt;
   &lt;id name="id"&gt;2&lt;/id&gt;
   &lt;firstname &gt;ddd&lt;/firstname&gt;
   &lt;lastname &gt;ggg&lt;/lastname&gt;     
   &lt;/Employee&gt;
   &lt;/Employees&gt;    
  </code></pre>
  
  <p>I am using the following script but getting error that An attribute node  cannot be create after the children of containing element.:</p>
  
  <p>Transform.xsl</p>
  
  <p><br>
          </p>
  
  <pre><code>&lt;xsl:template match="/"&gt;        
      &lt;xsl:apply-templates /&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="Employees/Employee/countryid[.=32']"&gt;
    &lt;xsl:attribute name="countryid"&gt;32&lt;/xsl:attribute&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:apply-templates select="@* | node()"/&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Any help will be appreciated. Also can we pass countryid as comma seprated values so that i can pass 32,100 and then it should add attribute to all the matching nodes.</p>
  
  <p>Thanks.</p>