How to display a URL hyperlink in a CQWP
By peter.stilgoe
In the relevant template section in itemstyle.xsl add a line something like (replacing the column name with the your column containing the URL):
LiveView: <a href="{substring-before(@Live_x005F_x0020_View, ',')}">Click here</a>
Sharepoint CQWP: XSL template to display document details
By peter.stilgoe
An example XSL template to display document details in a content query webpart:
<xsl:template name="DocumentsDetails" match="Row[@Style='DocumentsDetails']" 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="''"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
<xsl:with-param name="UseFileName" select="1"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayAuthor">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="''"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
<xsl:with-param name="UseFileName" select="1"/>
</xsl:call-template>
</xsl:variable>
<div class="item link-item">
<xsl:if test="string-length(@DocumentIconImageUrl) != 0">
<div class="image-area-left">
<a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
<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>
<img class="image" src="{@DocumentIconImageUrl}" title="" />
</a>
</div>
</xsl:if>
<div class="link-item">
<div style="color: black; font-family: Arial, Helvetica, sans-serif; line-height: -2%">
<xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
<a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
<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="$DisplayTitle"/>
</a> | <xsl:value-of select="@Author" /> | <xsl:value-of disable-output-escaping="no" select="ddwrt:FormatDate(string(@Description), 2057, 5)" />
</div>
</div>
</div>
</xsl:template>
A returned file in the CQWP will display:
Plan 36 | xxxxxx\StilgoeP | 01/06/2011 09:35
Doc Icon (links to doc) – Doc Title (links to doc) – Author – Modified Date & Time
More From pstilgoe
Sharepoint 2010 CQWP: Make the CQWP portable by using tokens to point to the current site instead of static URL
By peter.stilgoe
Target the CQWP to the current site export the CQWP, Edit & replace the WebUrl with below:
<property name="WebUrl" type="string">~Site</property>
To target the CQWP for the Site Collection its currently located on:
<property name="WebUrl" type="string">~sitecollection</property>
More From pstilgoe
Sharepoint CQWP: XSL to link document icon to document and open in edit mode
By peter.stilgoe
The xsl code will display & make the document icon link to the sepcific document & open it in edit mode in your content query webpart:
<a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
<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>
<img class="image" src="{@DocumentIconImageUrl}" title="" />
</a>
Sharepoint CQWP How to format date from mm/dd/yyyy to UK dd/mm/yyyy
By peter.stilgoe
To format your Sharepoint content query webpart to UK date format do the following:
In your ItemStyle.xsl add the following line to your declarations:
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
Then use the following line to display & format your date field in UK date format:
<xsl:value-of disable-output-escaping="no" select="ddwrt:FormatDate(string(@Modified), 2057, 5)" />
@Modified is your date field that you want to format
Using a CQWP to display items from a link list
By peter.stilgoe
If you point an OOTB CQWP to a Sharepoint Link List it will surface your links but each link will be displayed as (Blank) as its defaulting to display the Title column which is blank, it also links to the Link Item page as opposed to linking throught to the actual Link URL.
To fix this we need to:
1) Tell the CQWP to get the “URL” field from the list
- Add the CQWP to the page where you want to display the link list items
- Export the CQWP to a file (On the CQWP Edit menu click ‘Export’)
- Open the CQWP file in your editor & find
<property name="CommonViewFields" type="string" />
replace this with
<property name="CommonViewFields" type="string">URL,text</property>
(This is telling the CQWP to recognise the ‘URL’ column)
- Save this CQWP file & upload it back to you Web Part Gallery.
2) Create a new itemstyle for a link list that will render the link using the URL field instead of the URL to the link item page
- In your site collection goto
Site Library –> XSL Style Sheets –> ItemStyle.xsl
- Edit ItemStyle.xsl & add the template code below, add this below the last
</xsl:template>
in the file.
<xsl:template name="LinkList" match="Row[@Style='LinkList']" mode="itemstyle"> <xsl:variable name="DisplayTitle"> <xsl:call-template name="OuterTemplate.GetTitle"> <xsl:with-param name="Title" select="@URL"/> <xsl:with-param name="UrlColumnName" select="'URL'"/> </xsl:call-template> </xsl:variable> <xsl:variable name="LinkTarget"> <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if> </xsl:variable> <div id="linkitem" class="item" > <div class="bullet link-item"> <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/> <a> <xsl:attribute name="href"> <xsl:value-of select="substring-before($DisplayTitle,', ')"> </xsl:value-of> </xsl:attribute> <xsl:attribute name="title"> <xsl:value-of select="@Description"> </xsl:value-of> </xsl:attribute> <xsl:value-of select="substring-after($DisplayTitle,', ')"> </xsl:value-of> </a> </div> </div></xsl:template>
- Save the file & check back in
- Now go back to the page where you want to display links from a Sharepoint Link List & add your new webpart
- Open the webpart properties & goto Presentation –> Styles –> ItemStyle
- You should have the newly added ‘LinkList’ style, select this & click OK
Now your CQWP should be displaying your link list URLs as desired.
How to add extra fields to your CQWP that dont display as standard
By peter.stilgoe
1) Export your Content Query Web part to your desktop
2) Open it with Notepad and look for the following line of code:
3) Change this line to the following, and replace the portion MYINTERNALCOUMNNAME with the internal column name for your column
4) Save your file
5) Import the web part
- Edit page
- Add Web Parts
- Switch to advanced
- Switch from browse to import
- Browse to your file and upload you file
Now when you go to apply a filter, you will see your custom column.



November 15th, 2011
