I’m going to describe how we can use a Content Query Web Part to Style a SharePoint List. Let’s start with a SharePoint List Called Projects with the following fields.
As you probably already know the default look and feel would appear like this:
Now I’m going to render this list into a format similar to below:
First you need to define some names for these place holders (I know this may not make much sense to you. But don’t worry about it and please complete these steps). I’m going to define the columns as follows.
- Title –> MyTitle
- Logo –> MyLogo
- Project Summary –> MySummary
- Project Description –> MyDesc
Now you want to define a XSL Style Sheet using these names. Therefore I’m going to use <table> to layout the list item as below.
<xsl:template name="MyStyle" match="Row[@Style='MyStyle']" mode="itemstyle">
<td colspan="2"><h3><xsl:value-of select="@MyTitle" /></h3></td>
<xsl:value-of select="@MyLogo" />
<xsl:value-of disable-output-escaping="yes" select="@MySummary" />
<xsl:value-of disable-output-escaping="yes" select="@MyDesc" />
Here I used XSLT to position the content inside my html tags. There are a few attributes which are mandatory in this section. ;
- Name and Match should have equal names.
- name =’X’ match=Row[@style=’X’]
- mode = ‘itemstyle’
Now you have created XSLT which can be given as a list style in SharePoint.
Here we are going to put XSLT to SharePoint.
First you need to open SharePoint Designer with the particular site. Then navigate to All Files and Style Library.
You can see many Folders inside. Go to the XSL Style Sheet Folder.
You’ll see XSL files which are used by SharePoint to render its content. Here we are using ItemStyle.xsl for enabling custom rendering.
Open this xsl file and put your xsl (which we created in step two) at the bottom of the xsl as follows.
The hardest part is now over.
- Add a Content Query Web Part
- Go to edit web part and browse your list. (here our list is Our Projects)
- Then go to the presentation section and go a little bit down. You’ll see the style drop down.
- Wow .. Now you can see your style.
- Select your custom xsl (here MySample).
- Once selected you’ll see something like below.
- Now you need to add actual list column names to these text boxes as follows.(Title column should use the scope)
- Then Click ok to Save. You can see your new list rendering now.