How to bind XAttribute Value by Foreach
===


    var xEle = new XElement("ContentDetails",
                from emp in _lstContents
                select new XElement("Contents",
                            new XAttribute("key", emp.Key),
                            new XAttribute("PublishedDate", emp.PublishedDate),
                            new XAttribute("FilePathURL", emp.FilePathURL),
                            new XAttribute("ID", emp.TitleID),
                            new XAttribute("ContentName", emp.Name)
                            ));

_lstContents which contains whole records. i need to frame XmlDocument by LinQ operation
i know it could achievable and i done it.
This is my sample XML what i've done so:
    
    <ContentDetails>
      <Contents ContentName="Sample Project Plan SOW" ID="3"
            FilePathURL="http://192.168.30.59/contentraven/Uploads/Custom_View_LLC/EncryptedFile/zsg34g45tfblrkvzjh0cdlvs_17_7_2012_19_24_3.doc"
            PublishedDate="2012-07-10T14:37:02.073" key="310-072012-A5CDE"/>
    </ContentDetails>

but now what i need is
     
    <ContentDetails>
      <Contents ContentName="Sample Project Plan SOW" ID="3"
            FilePathURL="http://192.168.30.59/contentraven/Uploads/Custom_View_LLC/EncryptedFile/zsg34g45tfblrkvzjh0cdlvs_17_7_2012_19_24_3.doc"
            PublishedDate="2012-07-10T14:37:02.073" key="310-072012-A5CDE"/>
       <categories>
          <category id="1" categoryname="Category-1" contentid="3"/>
          <category id="2" categoryname="Category-2" contentid="3"/>
          <category id="3" categoryname="Category-3" contentid="3"/>
      </categories>
    </ContentDetails>

i'm trying something like this
    
    var xEle = new XElement("ContentDetails",
                from emp in _lstContents
                select new XElement("Contents",
                            new XAttribute("key", emp.Key),
                            new XAttribute("PublishedDate", emp.PublishedDate),
                            new XAttribute("FilePathURL", emp.FilePathURL),
                            new XAttribute("ID", emp.TitleID),
                            new XAttribute("ContentName", emp.Name),
                                new XElement("Categories",
                                    new XElement("Category",
                                        new XAttribute("ID", emp.Category.ForEach(_P => _P.CategoryID ),
                                        new XAttribute("CategoryName", emp.Category.ForEach(_P => _P.CategoryName))
                                    )

                            ));

how could i achieve this?

emp.Category is a Property List in _lstContents List; 

i need to create number of CategoryName attribute as much found in emp.Category.

please refer the screenshot as enclosed.
Thank you

![enter image description here][1]


  [1]: http://i.stack.imgur.com/thXpJ.png