3

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>
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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