title: Dynamic column name in xslt 1.0 grouping
body: <p>I am using xslt 1.0 and would like to use dynamic column name inside the group, Kindly suggest me the options.</p>
  
  <pre><code>&lt;xsl:key name="district-by-state" match="District" use="concat(../../StateName, '+', TranslatedDistrictName)" /&gt; 
  </code></pre>
  
  <p>Like- If <strong>TranslatedDistrictName</strong> is NULL or empty then use <strong>DistrictName</strong> else use TranslatedDistrictName.</p>
  
  <p><strong>Code</strong></p>
  
  <p><strong>XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="State.xsl" ?&gt;
  
  &lt;StateData&gt;
  &lt;States&gt;
      &lt;State&gt;
          &lt;StateName&gt;State1&lt;/StateName&gt;
          &lt;Districts&gt;
              &lt;District&gt;
                  &lt;TranslatedDistrictName&gt;AT&lt;/TranslatedDistrictName&gt;
                  &lt;DistrictName&gt;A&lt;/DistrictName&gt;              
                  &lt;Population&gt;10000&lt;/Population&gt;              
              &lt;/District&gt;         
              &lt;District&gt;
                  &lt;TranslatedDistrictName&gt;AT&lt;/TranslatedDistrictName&gt;
                  &lt;DistrictName&gt;B&lt;/DistrictName&gt;      
                  &lt;Population&gt;5000&lt;/Population&gt;                   
              &lt;/District&gt;     
              &lt;District&gt;
                  &lt;TranslatedDistrictName&gt;AC&lt;/TranslatedDistrictName&gt;
                  &lt;DistrictName&gt;A&lt;/DistrictName&gt;
                  &lt;Population&gt;2000&lt;/Population&gt;               
              &lt;/District&gt;                 
          &lt;/Districts&gt;
      &lt;/State&gt;
      &lt;State&gt;
          &lt;StateName&gt;State2&lt;/StateName&gt;
          &lt;Districts&gt;
              &lt;District&gt;
                  &lt;TranslatedDistrictName&gt;AC&lt;/TranslatedDistrictName&gt;
                  &lt;DistrictName&gt;C&lt;/DistrictName&gt;
                  &lt;Population&gt;8000&lt;/Population&gt;               
              &lt;/District&gt;         
              &lt;District&gt;
                  &lt;TranslatedDistrictName&gt;AT&lt;/TranslatedDistrictName&gt;
                  &lt;DistrictName&gt;B&lt;/DistrictName&gt;      
                  &lt;Population&gt;5500&lt;/Population&gt;                   
              &lt;/District&gt;     
              &lt;District&gt;
                  &lt;TranslatedDistrictName&gt;AP&lt;/TranslatedDistrictName&gt;
                  &lt;DistrictName&gt;A&lt;/DistrictName&gt;
                  &lt;Population&gt;1000&lt;/Population&gt;               
              &lt;/District&gt; 
          &lt;/Districts&gt;
      &lt;/State&gt;
  &lt;/States&gt;
  &lt;/StateData&gt;
  </code></pre>
  
  <p><strong>XSLT</strong></p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"&gt;  
     &lt;xsl:key name="district-by-state" match="District" use="concat(../../StateName, '+', DistrictName)" /&gt; 
      &lt;xsl:template match="StateData"&gt;
          &lt;xsl:for-each select="States/State"&gt;                
                  &lt;xsl:variable name="stateName" select="StateName" /&gt;    
                  &lt;xsl:value-of select="$stateName" /&gt;                        
                  &lt;xsl:for-each select="Districts/District[count(. | key('district-by-state', concat($stateName, '+', DistrictName))[1]) = 1]"&gt;   
                      &lt;hr/&gt;
                      &lt;xsl:value-of select="$stateName"/&gt;
                      &lt;xsl:value-of select="DistrictName"/&gt;   
                      &lt;xsl:value-of select="sum(key('district-by-state', concat($stateName, '+', DistrictName))/Population)" /&gt;
                  &lt;/xsl:for-each&gt;
              &lt;hr/&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>