Kolten
Kolten

Reputation: 3503

How to: use a querystring parameter in Sharepoint Search XSL?

This is my very first attempt at dealing with XSL, so please be kind :)

I am modifying the SharePoint 2010 peoplesearch results page - specifically the "View in Organizational Browser" line. I have added the orgbrowser webpart to our main site and don't want to direct users to the mysite for this link.

Here is the modified code:

<a id="{concat($currentId, '_OrgBrowserLink')}" href="/search/pages/orgbrowser.aspx?accountname={string(accountname)}">&#187; <xsl:value-of select="$ViewHiearchyLabel" /></a>

The above code works fine. I find I am having problems adding the search results querystring parameter though. The parameter is "k".

Thanks all

Upvotes: 0

Views: 3388

Answers (1)

Kolten
Kolten

Reputation: 3503

Unfortunately, the People Search Results web part does not pass the current url as a parameter. It does, however, pass several other URL parameters that do contain the current query string. So the solution is to use one of those, parse out the value in the 'k' parameter and append it to the URL.

I used the $NameSortUrl XSL parameter.

I parsed out the value of the 'k' parameter by using the substring-before and substring-after functions and saving the value in a variable:

<xsl:variable name="kVal" select="substring-before(substring-after($NameSortUrl, 'k='), '&amp;')"/>

I then appended this value to the url like this:

<a id="{concat($currentId, '_OrgBrowserLink')}" href="/search/pages/orgbrowser.aspx?accountname={string(accountname)}&amp;k={$kVal}">

Note the use of HTML encoding to get the ampersand in the url (&).

Hopefully this is useful to someone else in the future.

Upvotes: 1

Related Questions