SharePoint custom field type + XSLT rendering
Hi,
As you know already, SharePoint 2010 uses an XSLT engine to render views & custom field types. You can still use CAML views but it defaults to XLST.
I've just built a custom field type whose the parent type was "Choice". While building the corresponding XSLT, I didn't find the "mode" I was supposed to use...So, in case, the same story happens to you, an easy way to know which mode you're supposed to use is to examine the out-of-the-box file delivered with any SharePoint installation.
I'm talking about this file:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl
When opening that file, you can look at the template called PrintField and this is what you'll find:
<xsl:choose>
<xsl:when test="$Type='DateTime'">
<xsl:apply-templates select="." mode="DateTime_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='Computed'">
<xsl:choose>
<xsl:when test="$Name='LinkTitle' or $Name='LinkTitleNoMenu'">
<xsl:apply-templates select="." mode="Computed_LinkTitle_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Name='LinkFilename' or $Name='LinkFilenameNoMenu'">
<xsl:apply-templates select="." mode="Computed_LinkFilename_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Name='DocIcon'">
<xsl:apply-templates select="." mode="Computed_DocIcon_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
<xsl:with-param name="folderUrlAdditionalQueryString" select="$folderUrlAdditionalQueryString"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Name='NameOrTitle'">
<xsl:apply-templates select="." mode="Computed_NameOrTitle_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Name='URLwMenu'">
<xsl:apply-templates select="." mode="Computed_URLwMenu_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Name='HealthReportSeverityIcon'">
<xsl:apply-templates select="." mode="Computed_HealthReportSeverityIcon_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Name='LinkDiscussionTitle' or $Name='LinkDiscussionTitleNoMenu'">
<xsl:apply-templates select="." mode="Computed_LinkDiscussionTitle_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Name='Threading' or $Name='BodyAndMore'">
<xsl:apply-templates select="." mode="Computed_body">
<xsl:with-param name="thisNode" select="$thisNode" />
<xsl:with-param name="Position" select="$Position" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="Computed_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$Type='Attachments'">
<xsl:apply-templates select="." mode="Attachments_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='User' or $Type='UserMulti'">
<xsl:apply-templates select="." mode="User_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='Note'">
<xsl:apply-templates select="." mode="Note_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='Text'">
<xsl:apply-templates select="." mode="Text_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='Number' or $Type='Currency'">
<xsl:apply-templates select="." mode="Number_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='Lookup' or $Type='LookupMulti' or $Type='WorkflowStatus'">
<xsl:apply-templates select="." mode="Lookup_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='URL'">
<xsl:apply-templates select="." mode="URL_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='CrossProjectLink'">
<xsl:apply-templates select="." mode="CrossProjectLink_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='Recurrence'">
<xsl:apply-templates select="." mode="Recurrence_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Type='AllDayEvent'">
<xsl:apply-templates select="." mode="AllDayEvent_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="@CAMLRendering='TRUE'">
<xsl:apply-templates select="." mode="CAMLRendering_body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="body">
<xsl:with-param name="thisNode" select="$thisNode"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
from which you can conclude that:
DateTime == DateTime_body
Computed == Computed_LinkTitle_body || Computed_LinkFilename_body || Computed_DocIcon_body || Computed_NameOrTitle_body || Computed_URLwMenu_body || Computed_HealthReportSeverityIcon_body || Computed_LinkDiscussionTitle_body || Computed_body
Attachments == Attachments_body
User || UserMulti == User_body
Note == Note_body
Text == Text_body
Number || Currency == Number_body
Lookup || LookupMulti || WorkflowStatus == Lookup_body
URL==URL_body
CrossProjectLink == CrossProjectLink_body
Recurrence == Recurrence_body
AllDayEvent == AllDayEvent_body
and for all the other types, the mode is body :).
All, you're sure? Actually yes but there is a trap, if you work with MultiColumn field types, then, you'll have to use the Note_body mode because MultiColumn actually inherits from Note in its field definition that you can find in:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML\fldtypes.xml
<FieldType>
<Field Name="TypeName">MultiColumn</Field>
<Field Name="ParentType">Note</Field>
<Field Name="UserCreatable">FALSE</Field>
<Field Name="Sortable">FALSE</Field>
<Field Name="Filterable">FALSE</Field>
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr><Column/></Expr>
<Case Value="">
</Case>
<Default>
<Column SubColumnNumber="0" HTMLEncode="TRUE"/>
</Default>
</Switch>
</RenderPattern>
</FieldType>
Happy coding

Comments
ListID
I need the listid of the current item that is rendering, I can not find it any where. Do you have an idea how I can get the listid?
What about Integer
What about Integer type?
mode="Number_body" doesn't work.
match
Are you sure the value of your match attribute is ok? For numbers, it should be Number_body. If you have troubles, you can always also try with just "body". Otherwise post your FLDTYPES & corresponding XSL to see if I can help