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've created a custom field according to the following walkthrough:

http://msdn.microsoft.com/en-us/library/ff606773.aspx

My field XML is as follows:

  <FieldType>
    <Field Name="TypeName">ReviewStatus</Field>
    <Field Name="ParentType">Choice</Field>
    <Field Name="TypeDisplayName">Review Status</Field>
    <Field Name="TypeShortDescription">Review Status</Field>
    <Field Name="UserCreatable">TRUE</Field>
    <Field Name="FieldTypeClass">MyFields.MyReviewStatusField, $SharePoint.Project.AssemblyFullName$</Field>
  </FieldType>

and my XSL is as follows:

  <xsl:template match="FieldRef[@Name='ReviewStatus']" mode="body">
    <xsl:param name="thisNode" select="." />
    <span style="background-color:lightgreen;font-weight:bold">
      <!-- <xsl:apply-templates select="$thisNode/@*"/> -->
      <xsl:value-of select="$thisNode/@*[name()=current()/@Name]"/>
    </span>
  </xsl:template >

Now my issue is this, if I deploy my custom field to the server, and add a column of this type to a list, SharePoint gives me the opportunity to give it a "Name" so perhaps I name it simply "Status". After some debugging I found the problem with this is that my XSL does not match because the "Name" is "Status" and not the TypeName "ReviewStatus" as I have programmed into my XML and my transform.

What is the proper way to ensure that my transform matches and give users the ability to change the field "Name"? Do I override SPField InternalName? What is the best way?

EDIT: I found an attribute @FieldType that I can use instead of @Name, it appears to behave as I want (so the match looks like this):

<xsl:template match="FieldRef[@FieldType='ReviewStatus']" mode="body">

How can I see all of the attributes on the FieldRef? I've tried the following but saw neither Name or FieldType in the result (I assume I need to tweak this slightly):

 <xsl:template match="FieldRef[@FieldType='ReviewStatus']" mode="body">
    <xsl:param name="thisNode" select="." />
    <span style="background-color:lightgreen;font-weight:bold">
      <xsl:apply-templates select="$thisNode/@*"/>          
    </span>
  </xsl:template >

  <xsl:template match="@*">
    <xsl:value-of select="name()"/>=<xsl:value-of select="."/><br/>
  </xsl:template>
share|improve this question

1 Answer 1

up vote 2 down vote accepted

In order to customize the Rendering of a Field on a List View the following match attributes in templates are commonly used:

FieldRef[@Name='#FieldInternalName#']
FieldRef[@ID='#FieldID#']

So, in your case instead of Field Internal Name (@Name) you could specify match attribute for Field ID, like

<xsl:template match="FieldRef[@ID='5a14d1ab-1513-48c7-97b3-657a5ba6c742']" mode="body">
    <xsl:param name="thisNode" select="." />
    <span style="background-color:lightgreen;font-weight:bold">
      <!-- <xsl:apply-templates select="$thisNode/@*"/> -->
      <xsl:value-of select="$thisNode/@*[name()=current()/@Name]"/>
    </span>
  </xsl:template >

Note: Specify your field ID for match attribute


FieldRef Element description may be found here

Hope this helps,

Vadim

share|improve this answer
    
This answer helped me alot. Here is my own thread: sharepoint.stackexchange.com/questions/74255/… and here, too: stackoverflow.com/questions/14058776/… Thank you very much! –  BGM Aug 4 '13 at 5:05

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.