I have a list definition in Visual Studio. Now I want to modify the rendering of the list views using XSL.
First I point my custom xsl file in the XslLink attribute in the list Schema.xml file:
<XslLink Default="TRUE">CustomLibrary.xsl</XslLink>
MailType is a custom column of type Choice and has the following options to choose: In, Out, Other.
I’d like to change two things:
- the way its values are displayed in the ListView: show icons instead of text
- the column header of the ListView: instead of the default DisplayName, I want custom text “In/Out”
Here is the XSL file:
<xsl:stylesheet
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:ddwrt2="urn:frontpage:internal"
xmlns:o="urn:schemas-microsoft-com:office:office">
<xsl:include href="/_layouts/xsl/main.xsl"/>
<xsl:include href="/_layouts/xsl/internal.xsl"/>
<xsl:template name="FieldRef_header.MailType" match="FieldRef[@Name='MailType']" mode="header">
<th nowrap="nowrap" scope="col" onmouseover="OnChildColumn(this)">
<xsl:attribute name="class">ms-vh2</xsl:attribute>
<xsl:call-template name="dvt_headerfield">
<xsl:with-param name="fieldname">
<xsl:value-of select="@Name"/>
</xsl:with-param>
<xsl:with-param name="fieldtitle">
<xsl:value-of select="'In/Out'"/>
</xsl:with-param>
<xsl:with-param name="displayname">
<xsl:value-of select="@DisplayName"/>
</xsl:with-param>
<xsl:with-param name="fieldtype">x:string</xsl:with-param>
</xsl:call-template>
</th>
</xsl:template>
<xsl:template name="FieldRef_body.MailType" match="FieldRef[@Name='MailType']" mode="body">
<xsl:param name="thisNode" select="."/>
<xsl:choose>
<xsl:when test="$thisNode/@*[name()=current()/@Name] = 'In'">
<img src="/_layouts/images/gbwwain.png" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
</xsl:when>
<xsl:when test="$thisNode/@*[name()=current()/@Name] = 'Out'">
<img src="/_layouts/images/gbwwaoof.png" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
</xsl:when>
<xsl:when test="$thisNode/@*[name()=current()/@Name] = 'Other'">
<img src="/_layouts/images/generaldocument.gif" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
</xsl:when>
<xsl:otherwise>
<span></span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The above file needs to be deployed to the {SharePointRoot}\Template\Layouts\XSL\ folder.