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

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" />
    </td>
</xsl:template>

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>
</xsl:template>

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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 --> 
</xsl:template>

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> 
</xsl:template>

Hope this helps,

Vadim

share|improve this answer
    
Thanks again, vgrem. I appreciate your providing me a good answer to accept. –  BGM Dec 25 '12 at 21:24

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.