Salvete! I have a list with a Choice field called "Scope". I want to add a class to that field using XSL, but I can't figure out how to get it to change. I want all the items in that field to get my css class, but also keep the ms-vb2 class. Here is my attempt:

I've gotten this far, but it doesn't seem to quite work.

<xsl:template match="FieldRef[@Name='Scope']" mode="Text_body">
    <xsl:param name="thisNode" select="."/>
    <td class="ms-vb2">
        <xsl:attribute name="class">mycssclass</xsl:attribute>
        <xsl:value-of select="$thisNode/@Scope" />

I tried this, too:

<xsl:template match="FieldRef[@Name='Scope']" mode="Choice_body">
    <xsl:param name="thisNode" select="."/>
    <td class="ms-vb2 RatingsCSStoken">{$thisNode/@Scope}</td>

Maybe I don't have the mode right? I've tried everything.

I am using a custom xsl file in the _layouts directory, and using the match to make changes to any column with that fieldref name.

[two months later] I am still stuck on this. Doesn't anyone have a clue?

1 Answer 1


In order to define Custom Rendering for a SPFieldChoice field in template for mode attribute should be used value body

In your case template would look like this:

<xsl:template match="FieldRef[@Name='Scope']" mode="body">
    <xsl:param name="thisNode" select="."/>
    <!-- Your custom rendering for choice field goes here --> 

Save your XSLT stylesheet in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\XSL, using the following naming convention: fldtypes_YourFieldTypeName.xsl

But keep in mind, specified template is intended for rendering field. HTML table cell element (TD) that contains field element

<td class="ms-vb2">

is rendered in parent template printTableCellEcbAllowed. For more details see Overview of XSLT List View Rendering System.

So, in your case it would be better specify CSS class not in TD, but to HTML element used to render field itself, for example:

<xsl:template match="FieldRef[@Name='Scope']" mode="body">
    <xsl:param name="thisNode" select="."/>
    <span class="RatingsCSStoken"><!-- Your custom rendering for choice field goes here --></span> 

Hope this helps,



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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