var xelement = XElement.Parse(@"
<root>
<contet id=""01"">
<period>
<startDate>2007-01-01</startDate>
<endDate>2007-12-31</endDate>
</period>
</contet>
<contet id=""04"">
<segment>
<eplicit Value=""Sample"">Member</eplicit>
</segment>
<period>
<startDate>2007-01-01</startDate>
<endDate>2007-12-31</endDate>
</period>
</contet>
<contet id=""13"">
<period>
<startDate>2006-01-01</startDate>
<endDate>2006-12-31</endDate>
</period>
</contet>
<SampleTag contetRef=""04"" >01234</SampleTag>
<SampleTag contetRef=""13"" >04556</SampleTag>
<SampleTag contetRef=""22"" >427000000</SampleTag>
<SampleTag contetRef=""19"" >427000000</SampleTag>
<SampleTag contetRef=""10"" >23450</SampleTag>
<SampleTag contetRef=""01"" >45890</SampleTag>
</root>");
var contextIds = from st in xelement.Elements("SampleTag")
join ct in
( xelement
.Elements("contet")
.Elements("period")
.Where (e => DateTime.Parse(e.Element("startDate").Value) >= new DateTime(2006,12,01) &&
DateTime.Parse(e.Element("endDate").Value) <= new DateTime(2008,12,31))
.Select (e => e.Parent.Attribute("id").Value)) on st.Attribute("contetRef").Value equals ct
select st.Value;