Column that show the title of an item and point to a lookup value?
-
09-12-2019 - |
Question
I have two lists, let's say "Parent" and "Child". There is a lookup in "child" list that point to "parent".
In a custom view of Child list, I'd like to have the title of "Child" display, with a link to a custom page with the Parent ID in the url.
In the custom XSL of my child view, I have written :
<a href="{$ServerRelativeUrl}/Pages/myPage.aspx?MyID={substring-before(@Parent., string( ';'))}" title="Open parent">
Open Parent
</a>
This is not working as expected, the myId argument is empty.
If I write instead :
<a href="{$ServerRelativeUrl}/Pages/myPage.aspx?MyID={@Parent.}" title="Open parent">
Open Parent
</a>
MyID equals 1;#1
, the value in SPFieldLookupValue form.
How can I properly extract the remote ID to build a link?
PS: I choose to use Xslt View webpart only for this purpose. If there is a better alternative solution do not hesitate to let me know.
Solution
I'd just break it down a bit and do the substring-before operation before using it to look at why your substring is going wrong.
<xsl:variable name="myId" select="substring-before(@Parent., ';')" />
Parent: <b><xsl:value-of select="@Parent."/></b><br />
myId: <b><xsl:value-of select="$myId"/></b><br />
<a href="{$ServerRelativeUrl}/Pages/myPage.aspx?MyID={$myId}" title="Open parent">
Open Parent
</a>