Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a unique scenario where I need to compare values for conditional formatting of my Content Query Web Part. In most circumstances this is pretty easy, and we thought this was working for the most part in our implementation.

SharePoint 2010 I am using a cqwp to show 9 items from one list. The list uses a managed metadata field. I compare this field to the page name (which I get from parsing the URL) using if statements and contains(@Metadata, $MetadataMatch) or not(contains(@Metadata, $MetadataMatch) to determine which items I highlight. The problem that comes in to play is that the Page name is Plan and the item I am pulling into the CQWP has a value called Project Management Plan it highlights the item. I cant do an equals for this because the @Metadata field could have multiple items. I tried checking to see if there is a ; prior to Plan then it would show but that doesn't work at all, even though it is part of the string. I know working with MM can be a pain for things like this but I am hoping there is some sort of fix or workaround. Ill update this with code once I get access to it again later this afternoon.

      <xsl:variable name="PageTitleLong">
                    <xsl:call-template name="OuterTemplate.GetPageNameFromUrlRecursive">
                            <xsl:with-param name="Url" select="$PageUrl" />
                    </xsl:call-template>
     </xsl:variable>
     <xsl:variable name="PageTitle">
            <xsl:value-of select="translate((substring-before($PageTitleLong, '.')), '-', ' ')" />
     </xsl:variable>
    <xsl:variable name="TitleNoSpace">
            <xsl:value-of select="translate(@Title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ','abcdefghijklmnopqrstuvwxyz')" />
    </xsl:variable>
    <xsl:variable name="MetadataMatch">
            <xsl:value-of select="$PageTitle" />
    </xsl:variable>
    <div class="EI-Disc-Outer">
        <table width="100%">
          <tr>
             <td width="32px">
                  <a href="{$SafeLinkUrl}" title="Click to view {$DisplayTitle}" >                                                    
                       <img src="/ip/ep/Style Library/Images/icons/{$TitleNoSpace}32x32.png" border="0">
                           <xsl:if test="contains(@Metadata, $MetadataMatch)">
                                   <xsl:attribute name="class"></xsl:attribute>
                           </xsl:if>
                           <xsl:if test="not(contains(@Metadata, $MetadataMatch))">
                                 <xsl:attribute name="class">EI-Disc-Opacity</xsl:attribute>
                           </xsl:if>                                                                         
                                                            </img>
                                                            </a>
                                                    </td>
share|improve this question

1 Answer 1

Try using EQUALS.

I know it feels wrong but I am pretty sure it works with Managed Metadata.

Added for clarification: As per the blog post here, a CQWP will allow you to use EQUALS to filter against a multi-value Managed Metadata field. To be fair, I have not tried this within the XSLT but worth a try.

However, a CQWP can also filter using PageFieldValue. I have used this a few times in a similar way to what you are suggesting by adding a Managed Metadata column to the content type then adding the field to the page layout. You can then do the filter directly in the CQWP using Column = [PageFieldValue: FieldName].

In your case, it could also be worth trying with [PageFieldValue: Title] given that you have this already.

share|improve this answer
    
Can you elaborate for a better quality answer? –  Mike Mar 28 '13 at 21:25
    
I am filtering by the PageFieldValue in web parts that need it but the requirement is to not filter out the content but to conditionally format the items so that they are still there but are essentially grayed out. The managed metadata field type doesnt work like a lookup or choice column would in the CQWP, it only allows for contains. I did give it a shot with equals in my if statement but that did not appear to work. –  Cory Mar 29 '13 at 12:02
    
My apologies, I did not read your question properly. Have you tried outputting the values of your variables to confirm how they are stored? –  Dave Paylor Mar 29 '13 at 12:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.