Displaying Links Lists’ URLs in a Content Query Web Part (CQWP) in SharePoint 2010

I was trying to use a Content Query Web Part in SharePoint 2010 today and display the URL column from a Links list. Oddly, there’s no out of the box style for this. A little Binging, an #SPHelp tweet, and I came to the conclusion that I needed to add a new style to ItemStyles.xsl in /Style Library/XSL Style Sheets.

This seems counter-intuitive; a Links list would seem to be a common type of list to use with CQWPs. But I guess not. This sort of thing with the CQWP is why I almost always just jump straight to the Data View Web Part (DVWP). I can build my own XSL libraries faster than trying to sort out the CQWP ones, but we’re aiming for as fully out of the box as possible in this project. So I needed to write some XSL. You know, out of the box.

Luckily, I found a post on the MSDN Forums with a nice XSL template to accomplish exactly what I wanted. Yay, InterWebs. I could have written this, but why, when it’s already been done?

   <xsl:template name="LinkList" match="Row[@Style='LinkList']" mode="itemstyle">
        <xsl:variable name="SafeLinkUrl">
            <xsl:call-template name="OuterTemplate.GetSafeLink">
                <xsl:with-param name="UrlColumnName" select="@URL"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="DisplayTitle">
            <xsl:call-template name="OuterTemplate.GetTitle">
                <xsl:with-param name="Title" select="@URL"/>
                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="TheLink">
   <xsl:value-of select="substring-before($DisplayTitle,',')"/>
        </xsl:variable>
        <div id="linkitem">
            <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
            <a href="{$TheLink}" target="_blank" title="This link opens in a new window">
            <xsl:value-of select="substring-after($DisplayTitle,',')"/>
            </a>
        </div>
    </xsl:template>

BTW, this works the same way in SharePoint 2007. I just get more hits if I say SharePoint 2010 these days. ;+)

Similar Posts

43 Comments

  1. Update to anonymous from 2012 – I needed this for 2013:

    1. Fields to Display > Link should read “Url [Custom Columns]”

    2. Fields to Display > Title should read “Notes [Custom Columns]”

    3. Use the “Notes” field as a replacement for the Description field

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.