SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom list definition that defines some view. These views are linked to a custom xsl file because of some formatting rules (red row when field X equals Y).

In this xsl, I'd like to add a link to a custom page with the ID of the item. The result should be : weburl/pages/mypage.aspx?id=123.

I have by now something like this, at the very end of my xsl file :

    <a href="../Pages/mypage.aspx?MyID={@ID}">

This is working from my site home page (which is /pages/home.aspx), but this won't work from the list itself because of the relative url.

  1. is the xsl approach the correct way to defines such link ?
  2. if yes, is there any token or similar way to create SPWeb relative url ?


share|improve this question
up vote 8 down vote accepted

If you're including correctly main.xsl in your template, use $ServerRelativeUrl global parameter.


  <a href="{$ServerRelativeUrl}/Pages/mypage.aspx?MyID={@ID}">

MSDN reference for XSLT global parameters available here:

All these global parameters are defined in the main.xsl file:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\XSL\main.xsl

share|improve this answer
That works like a charm. I definitively have to dive this part of SharePoint. Thanks a lot. – Steve B Jun 11 '12 at 15:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.