Skip to content

Tag: XSL

Using XSL to get the URL of the Current SharePoint Page for the Content Query Web Part

The Content Query Web Part (CQWP) is the Swiss army knife of SharePoint. I use it in all sorts of situations. Recently, I had a situation where I was displaying content from a central list on a series of decentralized sites. The content in the web part was being filtered by the site it was hosted on. When the users navigated to the site, all they saw were the items from the central list that pertained to the site they were on.

When the users clicked on the item in the result set, it opened the item. The problem was that when they closed the item, they would be returned to the source list, which was not what they expected.

The solution was to add the source URL parameter to the XSL that the CQWP used, but how would it know the site that should be returned? Thankfully, Spyral Out had already come across this requirement, and sorted it out. I repeat it here so that there is another source available. Here’s how to do it:

  1. Add the  NameSpace xmlns:ddwrt=”http://schemas.microsoft.com/WebParts/v2/DataView/runtime” at to the top of the xsl file (Usually ItemStyle.xsl) 
  2. Add a parameter “PageUrl “ <xsl:param name=”PageUrl” />  right below your namespace definitions
image

3. Assign this parameter along with the SafeLink URL to a variable, and then use the variable as the link target

<xsl:variable name=”DetailPageLink” select=”concat($SafeLinkUrl,’&amp;Source=’,$PageUrl)” />
<a href=”{$DetailPageLink}” title=”{@LinkToolTip}”>

Once done,users can click through to an item,edit it, and when saved or closed, they will be returned to the page hosting the web part.

1 Comment