UPDATE 2010-08-26: I’ve added this template to the SPXSLT project on Codeplex. There’s a bit more explanation there.
UPDATE 2010-04-27: Shalin Parmar pointed out in a comment below that I had a bug in the template where the separator would only be displayed between the first and second values. I’ve made a change to the template to fix this as well as to allow markup in the separator. Thanks, Shalin!
Here’s another little utility piece of XSL which I have used from time to time. It takes as its parameters the multi-select column’s value and a separator string. The template will replace every occurrence of the semi-colon (;) in the multi-select value with the separator string. This is another example of what you can pull off with recursion in your XSL templates.
Instead of seeing something like this:
if you pass in ‘ | ‘ as the separator, you’ll see
value1 | value2 | value3
<xsl:template name="MultiSelectDisplay"> <xsl:param name="MultiSelectValue"/> <xsl:param name="MultiSelectSeparator"/> <xsl:choose> <xsl:when test="contains($MultiSelectValue, ';')"> <xsl:value-of select="concat(substring-before($MultiSelectValue, ';'), $MultiSelectSeparator)" disable-output-escaping="yes"/> <xsl:call-template name="MultiSelectDisplay"> <xsl:with-param name="MultiSelectValue" select="substring-after($MultiSelectValue, ';')"/> <xsl:with-param name="MultiSelectSeparator" select="$MultiSelectSeparator"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$MultiSelectValue" disable-output-escaping="yes"/> </xsl:otherwise> </xsl:choose> </xsl:template>
If you found this post helpful, please consider visiting one or more of the advertisers on the page. Writing good, in depth blog posts takes time, and advertising revenue - though by no means large - helps to offset the effort.