Extracting text from a lookup field in a SharePoint 2013
-
01-10-2020 - |
Question
I switched from InfoPath to the Designer forms. In the list I have a Lookupfield that Points to another list. In the Control modes Edit and New the select boxes are created automatically using the usual elements
<SharePoint:FormField runat="server" id="ff6{$Pos}" ControlMode="Edit" FieldName="Betrieb" __designer:bind="{ddwrt:DataBind('i',concat('ff6',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Betrieb')}"/>
<SharePoint:FieldDescription runat="server" id="ff6description{$Pos}" FieldName="Betrieb" ControlMode="Edit"/>
The Problem arises in the ViewForm, where I usually use the following:
<xsl:value-of select="@Betrieb"/>
But since Betrieb is a Lookup field, it creates an a element and in the form i see:
<a href="http://portal/projects/buchungsportal/_layouts/15/listform.aspx?PageType=4&ListId={f1b5206b-3d88-4ea3-8aba-6c26b9dd07f8}&ID=1146&RootFolder=*">THE VALUE I WANT TO DIAPLAY</a>
How do I extract only THE VALUE I WANT TO DISPLAY
?
Solution
You need to use the substring options available in XSLT to get what you want substring-before and substring-after. Like this:
<xsl:value-of select="substring-before("≤/a>", substring-after("*">", @Betrieb))"/>
Not fully tested, the encodings might be off for the greater than, less than, and double quote characters.
Edit: This also works, it will render a hyperlink though, not the value.
OTHER TIPS
select above should be:
substring-before(substring-after(@Lookup, '>'), '</a>')