title: how to style table row using XSLT
body: <p>I have this working xslt but have the issue to show alternative color on table rows. the row color is coming but not alternative row's because of the recursive its getting effected after parent tag is completed </p>
  
  <p>can you please help me</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><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"&gt;
  
  &lt;xsl:strip-space elements="*"/&gt;
  &lt;xsl:template match="/"&gt;
     &lt;html&gt;
     &lt;body&gt;
     &lt;table border="1"&gt;
      &lt;xsl:apply-templates select="*"/&gt;
     &lt;/table&gt;
     &lt;/body&gt;
     &lt;/html&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="*[text()]"&gt;
  
    &lt;xsl:variable name="altColor"&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test="position() mod 2 = 0"&gt;#FFFFFF&lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;#D3DFEE&lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:variable&gt;
    
    &lt;tr bgcolor="{$altColor}"&gt;
      &lt;td&gt;
      &lt;xsl:for-each select="ancestor-or-self::*"&gt;
          &lt;xsl:value-of select="name()" /&gt;
          &lt;xsl:if test="position()!=last()"&gt;
              &lt;xsl:text&gt;_&lt;/xsl:text&gt;
          &lt;/xsl:if&gt;
      &lt;/xsl:for-each&gt;
      &lt;/td&gt;
      &lt;td&gt;
      &lt;xsl:value-of select="." /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
      &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt;
      &lt;xsl:apply-templates select="*"/&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>input sample xml is this </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml-stylesheet type="text/xsl" href="xmltohtmlrecurnewfromAns.xsl"?&gt;
  &lt;A&gt;
     &lt;B&gt;Text&lt;/B&gt;
     &lt;C&gt;Text&lt;/C&gt;
     &lt;D&gt;
        &lt;D1&gt;Text&lt;/D1&gt;
        &lt;D2&gt;
            &lt;D3&gt;Text&lt;/D3&gt;
            &lt;D4&gt;Text&lt;/D4&gt;
        &lt;/D2&gt;
     &lt;/D&gt;
     &lt;E&gt;
        &lt;E1&gt;
            &lt;E2&gt;
                &lt;E3&gt;Text&lt;/E3&gt;
            &lt;/E2&gt; 
        &lt;/E1&gt;
     &lt;/E&gt;
  &lt;/A&gt;</code></pre>
  </div>
  </div>
  </p>