Thursday, May 7, 2015

Cannot Edit Content Query Webpart

One of our clients who use SharePoint 2010 as a publishing solution (Internet) had an issue where they suddenly couldn't edit a content query webpart on a publishing page. The webpart can be added and displayed correctly, but not edited. It's slightly customized, containing a predefined query that's grabbing items from a list. Trying with a vanilla CQWP didn't make any difference though. Creating a new page and trying the same still did not succeed.

Whenever they tried to edit the webpart, they'd get Unexpected Error.


Looking at the ULS logs, I stumbled upon this:

System.Xml.XmlException: Reference to undeclared entity 'nbsp'. Line 1027, position 40.   
 at System.Xml.XmlTextReaderImpl.Throw(Exception e)    
 at System.Xml.XmlTextReaderImpl.HandleGeneralEntityReference(String name, Boolean isInAttributeValue, Boolean pushFakeEntityIfNullResolver, Int32 entityStartLinePos)    
 at System.Xml.XmlTextReaderImpl.ResolveEntity()    
 at System.Xml.XmlLoader.LoadEntityReferenceNode(Boolean direct)    
 at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)    
 at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)    
 at System.Xml.XmlDocument.Load(XmlReader reader)    
 at System.Xml.XmlDocument.LoadXml(String xml)    
 at Microsoft.SharePoint.Publishing.WebControls.CmsDataFormWebPart.GetXslFile(String templateFileUrl)    
 at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.createItemStyleList()    
 at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.get_ItemStyleList()    
 at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.createAllSlotNames()    
 at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.get_AllSlotNames()    
 at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.createFieldsToDisplayControlGroup()    
 at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.createConfigureLayoutSectionControls()    
 at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.CreateChildControls()    
 at System.Web.UI.Control.EnsureChildControls()    
 at System.Web.UI.Control.PreRenderRecursiveInternal()    
 at System.Web.UI.Control.PreRenderRecursiveInternal()    
 at System.Web.UI.Control.PreRenderRecursiveInternal()    
 at System.Web.UI.Control.PreRenderRecursiveInternal()    
 at System.Web.UI.Control.PreRenderRecursiveInternal()    
 at System.Web.UI.Control.PreRenderRecursiveInternal()    
 at System.Web.UI.Control.PreRenderRecursiveInternal()    
 at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

So it seems somebody tried to insert an interval somewhere along the customizations. Looking further into the error, it seems it comes from the ItemStyle stylesheet. I grabbed it from the farm and saw there was   at one location. By default, the   would not be rendered when inserted in the XSL.

There are three quick ways to overcome this.

1. Change   to &#160

2. Change &nbsp to <![CDATA[&nbsp;]]>

3. Insert this in the XSLT file:

<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>

We chose solution 1 and it works like a charm. Content Query webparts can now be edited,.