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):
- <xsl:template name="CustomStyle" match="Row[@Style='CustomStyle']" mode="itemstyle">
- <table border='0'>
- <tr>
- <img height="220px;">
- <xsl:attribute name="src">
- <xsl:value-of select="@MyImg" />
- </xsl:attribute>
- </img>
- </tr>
- <tr>
- <td >
- <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"
- /></p></td>
- </td>
- </tr>
- </table>
- </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.