Use Content Query Webpart and View Content Dynamically Using Custom XSL Templates in SharePoint

This article explains how to use a content query webpart and view the content dynamically using custom XSL Templates.

Create a team site in SharePoint 2013.

Create a team site in SharePoint 2013

Open a site in SharePoint designer to add a new XSL style template.

Click on All Files.

Open a site in SharePoint designer

Just navigate to the Style library.

Click on All Files

Click on the XSL Style Sheet folder.

all files

Right-click on the itemstyle.xsl to “Check Out”.

itemstyle

Now we will add our own custom style to the content query webpart.

Add the following code to the bottom.

code in the bottom

The following is the code (in this code I am just adding the image and content):

  1.   <xsl:template name="CustomStyle" match="Row[@Style='CustomStyle']" mode="itemstyle">  
  2.       <table border='0'>  
  3.     <tr>  
  4.      <img height="220px;">  
  5.             <xsl:attribute name="src">  
  6.                 <xsl:value-of select="@MyImg" />  
  7.             </xsl:attribute>  
  8.             </img>  
  9.            </tr>  
  10.     <tr>  
  11.         <td >  
  12.            <td style="padding-left:10px; width:1300px;  font-family:Arial, Helvetica, sans-serif; font-size:16px;"><p style="text-align:justify" ><xsl:value-of select="@MyContent"   
  13. /></p></td>  
  14.         </td>  
  15.       </tr>  
  16.         </table>  
  17.  </xsl:template>  
I have just customized this code for my needs. Now it looks like this.

customized this code

Here I will create the new list for displaying the data dynamically using a content query webpart.

Click Add an app.

Create a custom list named new updates.

Create a custom list

Here I will create a columns named Image and Content.

create a columns

Content

Now the list looks like this.

Click on new item to add an image and the content.

add image and the content

new item image

Click Save. Now it look likes this.

news update

Now add a content query webpart to the page.

add a content query webpart in a page

Click Edit webpart.

Edit webpart

In the query section, select list or libraries to display the items dynamically.

query section select list

Just select New updates lists then click Save.

click Save

Now Select Presentation to apply the styles.

Select Presentation to apply the styles

Here you are able to see the custom style create on XSL Template.

Just select it.

In the image field just pass the column name from the list.

column name from the list

Now it looks like this.

new update

Here now I will change the image in the table.

new item

Now it has been updated and viewed in a custom style.

This will help you to dynamically view the content in SharePoint without writing code.

Happy SharePoint.