Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 :

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

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 ?

thanks

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

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

Example:

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

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
add comment

Your Answer

 
discard

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.