Xsl view, web relative link?
-
09-12-2019 - |
Question
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.
- is the xsl approach the correct way to defines such link ?
- if yes, is there any token or similar way to create SPWeb relative url ?
thanks
Solution
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