Home > Content Query, SharePoint, Web Parts, XSL, XSL > Get Current Page URL using XSL for Content Query Web Part

Get Current Page URL using XSL for Content Query Web Part

I frequently write custom XSL templates for Content Query Web Part (CQWP) for Rolling up List Items. I use  CopyUtil.aspx for link items to to Display Form Pages which on close or after editing the items takes you back to default list item page instead of where CQWP is located.

You can either fix this by

  1. opening a item new window (target =”_blank”  in your href’s )

<a href=”{$DetailPageLink}” title=”{@LinkToolTip}” target=”_blank”>

2. Using Source attribute in your URL. SharePoint ListForm Pages use this to navigate back to location you arrived .

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


3. The Problem with above approach is, If I am reusing this template at different location(page or Site) I would need to recreate this template to just change the source attribute. Also in case you are moving XSL files between environments it could break.

To fix it you can probably use JavaScript to get your current Page URL. I won’t go over this. I will be using often ignored ddwrt xml namespace. http://msdn.microsoft.com/en-us/library/aa505323.aspx (it is 2003 version article but most of the functions work ) and more http://weblogs.asp.net/soever/archive/2005/01/03/345535.aspx

 

We will be adding this namespace to your XSL file, you can add it to either Main CQWP xsl or ItemStyle.xsl, incase you add it to Main XSL pass it down to Item Template as parameter.  I usually add to Item Style XSL .

  1. Add NameSpace xmlns:ddwrt=”http://schemas.microsoft.com/WebParts/v2/DataView/runtime” at top
  2. Add a parameter “PageUrl<xsl:param name=”PageUrl” />  right below your namespace definitions
image 
3. Concat this parameter as part in your Display URL as part Source query string parameter

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

Related Posts

Display all Fields + Value

http://www.sharepointblogs.com/rohan/archive/2008/08/12/content-query-web-part-display-all-fields-values.aspx

About these ads
  1. uma
    August 5, 2009 at 5:23 pm | #1

    Hi,
    Thanks for the solution.I have been searching for the solution for a long time.Thanks a lot.

    I have question :
    How can we add a “new Announcement link ” to CQWP.

  2. Naresh
    October 16, 2009 at 6:43 am | #2

    HI,

    is there any way to get the “Webpart Title” using the XSLT in Content Query Webpart.

    I can get the PageUrl and Webpart Id using parameters

    but could not get any of the webpart properties, where I am specifically looking to get the “Web Part Title URL” and “Web part Title”
    as i have Links in the webpart Body that will link based on values in these two properties.

    please, please let me know if you have anywork around to get the webpart Title URL and WEbpart Title using XSl from any of the xsl files out there in sharepoint[contentquerymain.xsl, Itemstyle.xsl, Header.xsl]..

    Thank you.

  1. March 17, 2009 at 1:53 am | #1
  2. August 4, 2010 at 11:54 pm | #2
  3. January 19, 2011 at 9:55 pm | #3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: