Name

MultiSelectDisplay

Notes

This template lets you display the values in a multiselect column "nicely", using a separator of your choosing. You pass it a multi-select column value and the separator character(s).

Example

This example would return the values in the States column with the ';' separator replaced by the vertical bar '|'.

<xsl:variable name="NiceDisplay">
  <xsl:call-template name="MultiSelectDisplay"> 
    <xsl:with-param name="MultiSelectValue" select="@States"/>
    <xsl:with-param name="MultiSelectDelimiter" select="';'"/>
<xsl:with-param name="MultiSelectSeparator" select="'|'"/>
</xsl:call-template> </xsl:variable>

Code

    <xsl:template name="MultiSelectDisplay"> 
        <xsl:param name="MultiSelectValue"/> 
        <xsl:param name="MultiSelectDelimiter"/> 
        <xsl:param name="MultiSelectSeparator"/> 
        <xsl:choose> 
            <xsl:when test="contains($MultiSelectValue, $MultiSelectDelimiter)"> 
                <xsl:value-of select="concat(substring-before($MultiSelectValue, $MultiSelectDelimiter), $MultiSelectSeparator)" disable-output-escaping="yes"/> 
                <xsl:call-template name="MultiSelectDisplay"> 
                    <xsl:with-param name="MultiSelectValue" select="substring-after($MultiSelectValue, $MultiSelectDelimiter)"/> 
                    <xsl:with-param name="MultiSelectDelimiter" select="$MultiSelectDelimiter"/> 
                    <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>

Last edited Jan 6, 2012 at 2:11 AM by sympmarc, version 13

Comments

tchmiel Aug 21, 2012 at 6:26 PM 
jtandrew,

I solved this on a similar issue with multiple select people picker not displaying properly, but modifying the MultiSelectDisplay template as follows:

<!-- http://spxslt.codeplex.com -->
<xsl:template name="MultiSelectDisplay">
<xsl:param name="MultiSelectValue"/>
<xsl:param name="MultiSelectDelimiter"/>
<xsl:param name="MultiSelectSeparator"/>
<xsl:choose>
<xsl:when test="contains($MultiSelectValue, $MultiSelectDelimiter)">
<xsl:variable name="before" select="substring-before($MultiSelectValue, $MultiSelectDelimiter)"/>
<xsl:if test= "string(number($before))='NaN'">
<xsl:value-of select="concat($before, $MultiSelectSeparator)" disable-output-escaping="yes"/>
</xsl:if>
<xsl:call-template name="MultiSelectDisplay">
<xsl:with-param name="MultiSelectValue" select="substring-after($MultiSelectValue, $MultiSelectDelimiter)"/>
<xsl:with-param name="MultiSelectDelimiter" select="$MultiSelectDelimiter"/>
<xsl:with-param name="MultiSelectSeparator" select="$MultiSelectSeparator"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:if test= "string(number($MultiSelectValue))='NaN'">
<xsl:value-of select="$MultiSelectValue" disable-output-escaping="yes"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

and calling it as follows:

<xsl:call-template name="MultiSelectDisplay">
<xsl:with-param name="MultiSelectValue" select="@AssignedTo"/>
<xsl:with-param name="MultiSelectDelimiter" select="';#'"/>
<xsl:with-param name="MultiSelectSeparator" select="' | '"/>
</xsl:call-template>

This workaround will fail if a value in the multi select is actually a number.

Originally I tried to just display every second value, but on occasion, I found that one of the values did not start with a numberic value first. ( Name1;#242;#Name2;#342),

HTH

And thanks, Marc, keep up the good work - this and your SPServices project (http://spservices.codeplex.com/) have helped me alot!
Tom

MikeWilliams Aug 7, 2012 at 8:29 PM 
Hello Marc,

I may have a slight different requirement. This is the code there in the SharePoint Designer Edit mode: <xsl:value-of select="@Multiple_x0020_Associated_x0020_" disable-output-escaping="yes" />
It's just a multiple lookup select in a Custom Form. I want each selection to be put on a separate line and hyperlinked to the same URL, but a different "ID=#"; Based on the lookup Title they Select.

Multiple Associated Objectives
Link A
Link B
Link C
Etc.

Any help would be appreciated.

Mike Williams

iOnline247 Jul 26, 2012 at 1:17 PM 
Hi cneha,
Can you start a discussion thread and post the code you've tried previously? It'll be much easier to help you...

Cheers,
Matt

cneha Jul 26, 2012 at 9:05 AM 
Hi Marc,

I am using the "Group Work Site" template that comes with the Sharepoint Designer 2010. I have a multi select control which allows to select resources from the "Resources" list and save it to "group calendar" list. The values get stored in the format Resource1;Resource2;Resource3;.....
I need to be able to get the individual resource names from this string.
I tried various approaches..including the one above...but something seems to be wrong.

Can I use this template in this "Group Work Site" template that I am using?

Any help will be appreciated.

Thanks in advance.

jtandrew Jul 14, 2011 at 11:56 PM 
Hey Marc,
This awesome to begin with. I am hoping you can help me out with something. My multiselect returns the values like the following:

24;#PMA;#10;#Trademark;#11;#Triage;#21;#AMP;#22;#Appeals;#23;#Bypass;#25;#Publisher;#26;#QRT

I would like the values such as PMA, Trademark, etc. I do not want the numbers.

HELP! Thanks much
Jim