SharePoint 2010 – Creating a Content Query Web Part (CQWP) Link Target
The Content Query Web Part (CQWP) is a powerful feature in the SharePoint WebPart toolbox. You can use it to roll-up content from a variety of list sources and then display the content using some pre-set display options. You can even manipulate the XSL for the display to change the overall output.
One thing I noticed was missing when rolling up Link Lists, is the ability to define a target for the link. You can, of course, go into the XSL for the display output and hard-code target=”_blank”, however this results in an ‘all or nothing’ situation. Instead I wanted to create a field in the Link List called ‘LinkTarget’ and allow the users to choose whether the link should open in a new page or in the current window.
When you setup a CQWP and point to a Links List it allows you to define a few fields of data in the output: ‘Title’ and ‘Link’ (unless you have an image as part of your link). This is fine, however we also want to provide a target value. I’m sure there’s way to hack at the webpart and do something creative with the XSL, however I’ve come up with a much simpler method using a calculated field.
Create Your List Fields
In your Links List Settings create the following columns:
| Column Name | Column Type | Comments |
| DisplayGroup | Single Line of Text | |
| DisplayName | Single Line of Text | |
| LinkURL | Hyperlink | I renamed the standard URL field |
| LinkTarget | Choice | Choices should include _blank |
| NewTitle | Single Line of Text | =DisplayName&”|”&LinkTarget |
Now add your CQWP in a webpart page, setup the data sources and use the following presentation:

Now you need to open up SharePoint Designer and manipulate the ItemStyle.xsl. The file can be located here:

Once you have opened up the ItemStyle.xsl file, navigate to the template called ‘Bullets’ and add the following custom code so that your end result will look like this:
<xsl:template name="Bullets" match="Row[@Style='Bullets']" mode="itemstyle">
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="@Title"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="TargetText"><xsl:value-of select="substring-after($DisplayTitle,'|')"/> </xsl:variable>
<div class="item link-item bullet">
<xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
<a href="{$SafeLinkUrl}" title="{@LinkToolTip}" target="{$TargetText}">
<xsl:if test="$ItemsHaveStreams = 'True'">
<xsl:attribute name="onclick">
<xsl:value-of select="@OnClickForWebRendering"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'">
<xsl:attribute name="onclick">
<xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="substring-before($DisplayTitle,'|')"/> </a>
</div>
</xsl:template>
Publish the ItemStyle.xsl and you’re all done. You now have bulleted links with the ability to control the link target.
Enjoy!