Retrieve Web part Title in Contentquerymain.xsl

To retrieve webpart title in Contentquerymain.xsl, You can use Feed Title web part property.
To achieve this you need to add

<xsl:param name="FeedTitle" />

to your custom ContentQueryMain.xsl in the params section.

Doing this the param FeedTitle will contain the web part Title and can be used inside xsl as below code

<xsl:value-of select="$FeedTitle" />


calendarMarch 12, 2012 · cardInfoyen · comments7 Comments
tagTags: , , , ,  · Posted in: CQWP, MOSS, SharePoint

7 Responses

  1. Sebastien - June 27, 2012


    I am a beginner in Webpart programming in Sharepoint 2010 and I can not do what I want concerning the display of my webpart. I wish to display the title of the webpart not in a title (of type h3) but in a li. Could you help me to do this, because I can not do it.

    I tried your solution but I do not know where to place the code.

  2. Infoyen - June 28, 2012


    My article is about “Contentquerymain.xsl” which is used for out of the box (OOB) “Content Query web part”.
    “Contentquerymain.xsl” provide the display layout for “Content Query web part”.
    If you want to customize “Contentquerymain.xsl” to change layout and if you require webpart title value in this file for any business requirement then you can use my article.

    However Your question is not clear to me.

    Which web part you are using? Is it custom web part or is it Content Query web part?

    1. If its custom web part, then you can disable web part title using editor tool part.
    (modify your web part, open Appearance, go to Chrom type then change it to None)
    and display title in your webpart code (in create child control method) as you required using c# code.

    2. If you are using ContentQuery web part; then you need to go to xsl library:- “http://localhost/Style Library/Forms/AllItems.aspx” then click on “XSL Style Sheets” folder. Then change ItemStyle.xsl” file.
    Here find your template which is selected in your web part and change style sheet.

    Hope it gives you idea.


  3. Sebastien - June 28, 2012

    Hello, Many thanks for your quick response. In fact I created a new style (item style in ItemStyle.xls) and a webpart (basis on this style). Therefore this webpart allows to display a list of files from a library thanks to filters defined in the parameters of the query of the webpart.

    On my page I apply a specific page layout (with several webpart zones) , I inserted several webpart defined with the ne item style and basis on different parameters for listing specific files.

    For example my page displays

    webpart1 in webpartzone 1
    title: Projects (appearence parameter on default)

    contract 1 Title
    – Contract signed on xxxx-xx-xx
    – Amendment 1 signed on xxxx-xx-xx
    – Amendment 2 signed on xxxx-xx-xx
    contract 2 Title
    – Contract signed on xxxx-xx-xx
    – Amendment 1 signed on xxxx-xx-xx
    – Amendment 2 signed on xxxx-xx-xx

    webpart2 in webpartzone 2
    title: Tenders

    contract 1 Title
    – Contract signed on xxxx-xx-xx
    – Amendment 1 signed on xxxx-xx-xx
    – Amendment 2 signed on xxxx-xx-xx
    contract 2 Title
    – Contract signed on xxxx-xx-xx
    – Amendment 1 signed on xxxx-xx-xx
    – Amendment 2 signed on xxxx-xx-xx

    My purpose is to hide or show the contents of the webparts by clicking on the title (here: Projects, tenders) thanks to a javascript script.
    My script uses ul and li to show and hide the content.

    In the HTML display of the page, the lines of results of each webpart appears in li (and it’s fine to show and hide the content for each contract), but the title appears in the webpart in a h3 type:


    I would like to replace the h3 type by a li to use the script on the title of the webpart for hidding ou showing his content.

    Otherwise I have tried to delete the webpartzones of the page layout and I have put the various webparts (without displaying the title) directly in the RichtextContent of the page by putting the li on my text. It’s works…Nevertheless I have javascript error when I place more than 4 webparts in the page… I think that’s is not the good solution…

    I don’t know how can I do this and where (in the page layout? in the Contentquerymain.xsl? or other)

    Could you please help me or tell me if you see another solution to make this?

    Many thanks in advance for your response.

  4. Infoyen - July 2, 2012


    I hope you might have get solution already. Still I am suggesting my solution here below:-

    My assumption: you are using ContentQueryWebpart (CQWP).

    First point: you need to write JavaScript which make your content visible or invisible. It may be like below:-

    [sourcecode language=”javascript”]
    function playhide() {
    var mainElement = "div[id$=’maindivelement’]"; // place your div id here

    if (mainElement == null) {
    return false;
    if ($(mainElement).is(":hidden")) {
    } else {
    return false;

    Second point: You need to insert this JavaScript and call on title link click.
    For this you need to edit ContentqueryMain.XSL where you will find that CQWP generate table structure for its content. Also you can check header.xsl(I am not sure will it require or not for you requirement)
    Create your own div element for your content. And call JS to make this div hide or show.

    Note: This is one of way to handle your situation. You may get some other solution too.

    How to insert javascript or jQuery in itemstyle.xsl or contentquerymain.xsl

    You may try in this manner
    [sourcecode language=”xml”]
    <xsl:template match="testtemplate">
    <script language="javascript" defer="true">
    $(document).ready( function() {

  5. Sebastien - July 5, 2012


    Many thanks for your help. I’m sorry for my late response… I have found a solution to solve my problem, and I managed to do what I want.

    First of all I created a customized master template in order insert my javascript in the head section.
    Then I have created a layout page in order to place the code in order to “all expand” and “all Contract” and to call the javascript function and to place the webpartzone.

    And I followed these steps:

    1 – Make a copy of the ItemStyle xsl file and the ContentQueryMain xsl file. I renamed the copy in CustomItemStyle.xsl and CustomContentQueryMain.xsl

    2 – Create a new page in my main site with the new page layout created above

    3 – Insert a new webpart content query. I configured the webpart by selecting the good list and other parameters. In particular I used the “None” chrome type in the “Appearance” section in the web part properties.

    4 – I exported the webpart and open that .webpart file with a XML editor and find the line which specifies the property with the name “ParameterBindings” and change that line into the following in order to create a new parameter “WebPartTitle”:

    <ParameterBinding Name=”WebPartTitle” Location=”WPProperty(Title)” />

    5 – In the CustomItemStyle.xsl file I have made updates to retrieve the field WebPartTitle (the code can not appear here).

    6 – I have equally specified the custom .XSL files created earlier by specifying them in the following properties. Therefore I have changed the lines “ItemXslLink” and “MainXslLink” by placing the link to path to the 2 costomized files

    7 – I uploaded the new webpart in my webpart gallery in Sitesettings options and inserted it in a new page:

    Best Regards,

  6. Viresh - November 27, 2012

    I would like to display a filter property within the itemstyle (filtervalue1).. how do I go about referncing this within the xsl? Is it possible? I know it’s possible to send other parameters like FeedTitle etc from the Content QueryMain, but can we do the same with a filter value?

  7. Infoyen - November 28, 2012

    I haven’t understand your full requirement. What i got is; you need to set some value (or FilterValue1) into XSLT variable. So that you can use this xsl variable value into item.xsl file.

    Below approach might help you:-


    1. you need to extend content query webpart. Please visit my below blog to learn about this:-

    2. After extending; set c# object value into xslt variable.
    This i never documented in my blog. Please refer below url. He described in detail.


Leave a Reply

Spam Protection: , required

myworldmaps infoyen