title: using xslt key for finding unique values
body: <pre><code>&lt;ROOT&gt;
  &lt;AA Aattr="xyz1"&gt;
      &lt;BB bAttr1="firefox"  bAttr2="aaa" &gt;
      &lt;/BB&gt;   
      &lt;BB bAttr1="chrome"   bAttr2="aaa" &gt;
      &lt;/BB&gt;
      &lt;BB bAttr1="firefox"  bAttr2="bbb" &gt;
      &lt;/BB&gt;
      &lt;BB bAttr1="chrome"   bAttr2="bbb" &gt;
      &lt;/BB&gt;
  &lt;/AA&gt;
  &lt;AA Aattr="xyz2"&gt;
      &lt;BB bAttr1="firefox"  bAttr2="aaa" &gt;
      &lt;/BB&gt;   
      &lt;BB bAttr1="chrome"   bAttr2="ccc" &gt;
      &lt;/BB&gt;
      &lt;BB bAttr1="firefox"  bAttr2="ddd" &gt;
      &lt;/BB&gt;
  &lt;/AA&gt;
  </code></pre>
  
  <p></p>
  
  <p>I want to select distinct\unique values of attibute 'bAttr2' in node 'BB', from node 'AA' where attribute 'Aattr' is xyz1</p>
  
  <p>say for the given xml, i need to output as "aaa","bbb"</p>
  
  <p>I tried the following logic using key. But didnt worked. Please help</p>
  
  <pre><code>&lt;xsl:key name="nameDistinct" match="BB" use="@bAttr1"/&gt;
  &lt;xsl:template match="/"&gt;
  &lt;xsl:for-each select="ROOT/AA[@Aattr='xyz1']"&gt;
      &lt;xsl:for-each select="BB[generate-id()=generate-id(key('nameDistinct',@bAttr2)[1])]"&gt;
      &lt;xsl:value-of select="@bAttr2"/&gt;            
      &lt;/xsl:for-each&gt;
  &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  </code></pre>