Saturday, November 17, 2012

using the people picker with multiple names in a cqwp

recently when displaying the value of a people picker column in a content query web part in SharePoint 2010, I encountered some odd behavior. namely, it separates multiple names with odd characters.

Popdan, David M;#14;#Doe, John M;#31;#Smith, Bill;#25;#Money, G.

I couldn't find a way to resolve it in SharePoint, but I was able to clean it up with a simple JavaScript function.

<script type="text/javascript">
     function CleanNames(text2clean) {
          return text2clean.replace(/[;#0-9]+/g, "; ");

Then call it from your XSL

<xsl:if test="string-length(@Contributors) != 0">
     <script type="text/javascript">document.write(CleanNames("<xsl:value-of select="@Contributors" />"));</script>

For now, that'll have to do.

1 comment:

  1. this is probably because regular expressions can't be called in SP2010 due to RegEx being native to XSL processor 2.0. It would appear that SP2010 uses and XSL processor of version 1.0. Stinks to have go through this process to do simple RegEx that have been around forever!!