title: Filtering out duplicate XElements based on an attribute value from a Linq query
body: <p>I'm using Linq to try to filter out any duplicate XElements that have the same value for the "name" attribute.</p>
  
  <p>Original xml:</p>
  
  <pre><code>&lt;foo&gt;
  &lt;property name="John" value="Doe" id="1" /&gt;
  &lt;property name="Paul" value="Lee" id="1" /&gt;
  &lt;property name="Ken" value="Flow" id="1" /&gt;
  &lt;property name="Jane" value="Horace" id="1" /&gt;
  &lt;property name="Paul" value="Lee" id="1" /&gt;
  ... other xml properties with different id's
  &lt;/foo&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>// project elements in group into a new XElement
  // (this is for another part of the code)
  var props = group.data.Select( f =&gt; new XElement("property", 
      new XAttribute("name", f.Attribute("name").Value), f.Attribute("value"));
  
  // filter out duplicates
  props = props.Where(f =&gt; f.ElementsBeforeSelf()
                            .Where(g =&gt; g.Attribute("name").Value ==
                                        f.Attribute("name").Value)
                            .Count() == 0);
  </code></pre>
  
  <p>Unfortunately, the filter step isnt working. I would think that Where() filter would check for any element before the current one that has the same property name and then include that  in a set that was more than zero, thereby excluding the current element (called 'f'), but thats not happening. Thoughts ?</p>