title: How to dynamically assign name and href for anchor tag in xsl
body: <p>I have a requirement where the xml might have one or more services (name might be different), and I am having a content which should have all of these available services from the xml  something like below</p>
  
  <pre><code>&lt;li&gt;&lt;a href="#_cms"&gt;CMS&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#_dis"&gt;DIS&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>but above I have hardcoded the <code>a</code> tag content and <code>href</code> since I know these are the values, but in real time I would not be knowing these names, so how to set <code>href</code> and <code>anchor tag contents</code> based on xml values?</p>
  
  <p>So far I got the below <code>for-each</code> statement, which gets me all the service names from the xml</p>
  
  <pre><code>&lt;xsl:variable name="number"&gt;
    &lt;xsl:number/&gt;
  &lt;/xsl:variable&gt;
  
  &lt;xsl:for-each select="csmclient/product/domainmetadata/domainmetadata_service"&gt;
      &lt;li&gt;&lt;a href="#_ser{$number}"&gt;&lt;xsl:value-of select="@name"/&gt;&lt;xsl:value-of select="position()"/&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;/xsl:for-each&gt;
  
  .
  .
  .
  
  &lt;!--far below end--&gt;
  &lt;xsl:for-each select="domainmetadata/domainmetadata_service"&gt;
      &lt;h3&gt;Service Name: &lt;span style="color:#328aa4"&gt;&lt;a name="_ser{$number}" href="#_top"&gt;&lt;xsl:value-of select="@name"/&gt;&lt;/a&gt;&lt;/span&gt;&lt;/h3&gt;
      .
      .
      .
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>but it does not seem to work, it gives me all my services but the link does not work. Any other ideas?</p>
  
  <p><b>Note</b>: I took help from <a href="https://stackoverflow.com/questions/7952572/how-to-increment-a-xsl-integer-variable">this question link</a> which had a similar requirement.</p>