Displaying a Multi-Select Column "Nicely"

1 minute read

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:

value1;value2;value3

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>
Advertisements

85 Comments

  1. Marc,
    Once you convert to XSLT do you have to point to your template file from within the Data View Properties screen under XSLT source? I too am trying to accomplish a line break and confused as to how to implement the code similar to the request of Bobby Noonan above.

    Your help is appreciated and thank you in advance

    Reply
    • Jim:

      You might want to look at the Usage Page in the documentation over at the SPXSLT Codeplex Project. I give some more information about how to use templates like this there.

      I also have a series of posts on NothingButSharePoint.com, duplicated here on my blog, which are also available as a nice eBook which explain the XSL tags available to you in DVWPs.

      M.

      Reply
  2. Hi!

    Is there an way to easily display nicely with TaxonomyFieldControl in SharePoint 2010?

    For example:

    displays:
    Value1;Value2;..ValueN

    I would like it to display:
    Value1
    Value2
    .
    .
    ValueN

    Thanks
    Ole

    Reply
    • Ole:

      The approach ought to be similar. Since the default display has clear delimiters, you should be able to use the same XSL template, just passing in different values for the parameters.

      M.

      Reply
  3. Marc,

    I see no one has commented on this topic in a while, but I’ve encountered this exact problem and your article here is the most helpful info I’ve found thus far. I’m hoping you can help me to.

    My problem is very similar to Fred’s in that I have a multi-select box in a list form that is a look-up from another table, where the field there is the title. When the form is submitted, I have a workflow that creates an entry in a discussion board and passes info from several of the fields. Of that info, are the values from the multi-select box, which get assigned to a variable and then updated in corresponding field of the discussion board. When I try to display them in the discussion board, they are displayed with in this format: 236;#Clone10;#237;#Clone11;#238;#Clone12;#…etc.
    So I tried the code you said would work for Fred and didn’t seem to change anything.

    I’m fairly new to SharePoint, so my first question is… do I have the script in the right place? I’ve placed it within the code of the NewForm.aspx towards the bottom after the body HTML. So in other words there is a XSL template section that contains the HTML for the form and then right after that template tag closes is where I placed your script. Should it be somewhere else?

    I would so appreciate hearing back from you, as you obviously seem to be familiar with this issue and I’d really like to find a solution.

    Please let me know If more info is needed or you have additional questions.

    Thanks,

    SS

    Reply
    • Steve:

      The code I show here is XSL which you can use in a Data View Web Part (DVWP), not script. You could certainly write some script to change the display on the client side, though.

      M.

      Reply
  4. Hi Marc,

    I want to group by the multiselect choice type column, if so could you please provide me the steps in doing that.

    Thank you in advance…

    Rajashekhar

    Reply
  5. Hi Marc. I do understand that we can’t utilize your tool in a CEWP. However, we are prevented from using SPD at our workplace. The closest thing I have is the little XML Web Part. Any suggestions on how I could employ your tool?

    Tx

    Carl

    Reply
  6. I can’t figure out where to put the template variables. I’m using SP 2007 and I place the xsl import immediately before the [xsl output method=”html”] line. I can click the link and it pulls up the XSL template file. Where then do I place the template block of code you have listed above? I’ve tried in a variety of places throughout the DVWP in Designer and each time I get an “Unable to display this Web Part” error. I’ve looked over the documentation at SPXSLT Codeplex page but I’ve not been able to find anywhere that shows a whole example page of code to see where should be placed. Thanks for any help you could provide in advance.

    Reply
      • Hi, I did take a look at that page. I think it may be useful for me to see a whole complete page so I can tell where those code segments are being placed in relation to the rest of the code. I feel like I’m missing a silly thing on my end although I’m not sure how different things are handled between 2007/2010/2013 when inserting these templates. Thanks!

        Reply
  7. Hi Marc

    I am also working on such a sharepoint 2010 requirement wherein i need to provide hyperlinks to multiple select options from a lookup column.
    If their is only one option selected its quite easy to provide hyperlink to it though if i have multiple options selected, i can’t get individual hyperlinks.
    Rather it gives combination of all the web addresses as hyperlink when mouse hover the options.
    Kindly provide any solution.

    Reply

Have a thought or opinion?