String Split Template

May 26, 2011 at 2:07 PM

I had originally placed this in the string replace thread, but I think it's a bit different and should be it's own.

Template:

<xsl:template name="StringSplit">
  <xsl:param name="val" />
   <xsl:choose>  
    <xsl:when test="contains($val, ';')">   
     <xsl:value-of select="substring-before($val, ';')" />
     <br />     
      <xsl:call-template name="StringSplit">     
       <xsl:with-param name="val" select="substring-after($val, ';')" />     
      </xsl:call-template>  
   </xsl:when>  
   <xsl:otherwise>      
    <xsl:value-of select="$val" />
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Usage:

<td class="ms-vb">    
  <xsl:call-template name="StringSplit">      
    <xsl:with-param name="val" select="@YourColumn" />
  </xsl:call-template>
</td>

May 26, 2011 at 2:12 PM

It is very similar to the MultiSelectDisplay, it's taking the values of a multiselect field, looking for the specified delimiter, and replacing it with a <br /> tag to put them on their own separate line in the cell. 

May 26, 2011 at 2:21 PM

And now that I look through the discussions, I see it's very similar to http://spxslt.codeplex.com/discussions/228867.  Alex and I must have been reading the same blogs.