1 minute read
A great way to manage the values for a Site Column in SharePoint is to put the values into a list and then use the Lookup column type to grab the values. When you allow multiple selections in the lookup column, what is stored looks something like this:
If you would like to then check in a DVWP to see if a value was selected, it’s not as simple as you’d like. If your values are truly unique and cannot be nested (e.g., School and Schoolhouse both contain the string School), then you can use contains. Otherwise, you’ll want to tighten things up a bit by doing some fancier matching.
The possible ways that we can have a match are:
- The multi-select string matches the value exactly. This is the case when there has been only one selection made, and it is the one that we want.
- The multi-select string begins with our value followed by a semicolon (value1;)
- The multi-select string has the target value in the middle, therefore surrounded by semicolons (;value2;)
- The multi-select column contains the value at the end, preceded by a semi-colon (;value4)
To test for each of these conditions, you just need a little logic in your XSL. Here’s an example that works when you want to see if MultiSelectColumn contains DesiredValue.
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[ @MultiSelectColumn= $DesiredValue or starts-with(@MultiSelectColumn, concat($DesiredValue, ';')) or contains(@MultiSelectColumn, concat(';', $DesiredValue, ';')) or substring(@MultiSelectColumn, string-length(@MultiSelectColumn) - string-length($DesiredValue), string-length($DesiredValue) + 1) = concat(';', $DesiredValue) ]"/>
Depending how you will need to do the test, consider creating a template that you can pass the multi-select string and the desired value, passing back the results of the test. You can store this template in a separate file and then use the template in many DVWPs by including it with xsl:import.