Monday, April 12, 2010

Lookup Fields and XSL

Ahh, XSL...Cause of and solution to all of SharePoint's formatting woes.

I'm displaying a document library in an XSLT data view on my SharePoint page, and one of the fields I want to show is a lookup type.

Now, lookup type field values are stored with both the string value and the ID, like so:

17;#Value


...Which is fine, right up until you try to include that field in your data view, and get pages of 17#;Value, 18#;AnotherValue, etc.

Thankfully, XSL provides its own solution. Use the substring-after command to strip out those pesky IDs....Or, conversely, use substring-before if you just want the IDs!


Code sample:


<xsl:value-of select="substring-after(@Fieldname, ';#')" />

No comments:

Post a Comment