3

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

1 Answer 1

9

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

1
  • That works like a charm. I definitively have to dive this part of SharePoint. Thanks a lot.
    – Steve B
    Commented Jun 11, 2012 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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